修改file1.txt后,
$git status
显示file1有改动,如果不想要刚才的改动。
$ git checkout -- file1.txt
file1恢复到改动之前。
如果想保留刚才的改动,再次 git add file1.txt, 然后 git commit -m "..........................."
$ git diff readme.txt
修改内容后,查看改动内容
$ git log
查看每次提交
$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed
上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
******http://www.git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History******
$ git log
$ git log -p -2
$ git log -U1 --word-diff
$ git log -U1 -p -2 --word-diff
$ git log --stat
$ git log --pretty=oneline
$ git log --pretty=format:"%h - %an, %ar : %s"
Option | Description of Output |
---|---|
%H | Commit hash |
%h | Abbreviated commit hash |
%T | Tree hash |
%t | Abbreviated tree hash |
%P | Parent hashes |
%p | Abbreviated parent hashes |
%an | Author name |
%ae | Author e-mail |
%ad | Author date (format respects the --date= option) |
%ar | Author date, relative |
%cn | Committer name |
%ce | Committer email |
%cd | Committer date |
%cr | Committer date, relative |
%s | Subject |
Option | Description |
---|---|
-p | Show the patch introduced with each commit. |
--word-diff | Show the patch in a word diff format. |
--stat | Show statistics for files modified in each commit. |
--shortstat | Display only the changed/insertions/deletions line from the --stat command. |
--name-only | Show the list of files modified after the commit information. |
--name-status | Show the list of files affected with added/modified/deleted information as well. |
--abbrev-commit | Show only the first few characters of the SHA-1 checksum instead of all 40. |
--relative-date | Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format. |
--graph | Display an ASCII graph of the branch and merge history beside the log output. |
--pretty | Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format). |
--oneline | A convenience option short for --pretty=oneline --abbrev-commit . |
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
****************http://www.git-scm.com/book/en/Git-Basics-Working-with-Remotes********************
$ git remote
$ git remote -v
$ git remote add pb git://github.com/paulboone/ticgit.git
$ git fetch [remote-name]
$ git push origin master
$ git remote rename pb paul
$ git remote rm paul
****************http://www.git-scm.com/book/en/Git-Basics-Tagging************************
$ git tag
$ git tag -l 'v1.4.2.*'
$ git tag -a v1.4 -m 'my version 1.4'
*********************http://www.git-scm.com/book/en/Git-Branching-What-a-Branch-Is*********************
Staging the files checksums each one (the SHA-1 hash we mentioned in Chapter 1), stores that version of the file in the Git repository (Git refers to them as blobs), and adds that checksum to the staging area:
$ git branch testing
$ git checkout testing
$ git checkout -b iss53
Switched to a new branch 'iss53'