譯者:zhanhailiang 日期:2015-01⑵1
原文鏈接:25 Tips for Intermediate Git Users
拋棄暫存區(qū)的所有操作:
$ git stash
# Do something...
$ git stash pop
$ git add -i
staged unstaged path
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now>
略.
查看最近提交的操作日志:
$ git log -p
只查看最近修改的文件列表:
$ git log --stat
查詢指定作者的更新日志:
$ git log --author=Andy
通過搜索提交的注釋關(guān)鍵字過濾日志:
$ git log --grep="Something in the message"
查詢指定文件的修改日志:
$ git log lib/foo.rb
查看分支feature/132與分支feature/145,其各自與master分支的區(qū)分:
$ git log feature/132 feature/145 ^master
也能夠查詢指定時(shí)間段內(nèi)(該時(shí)間格式支持ActiveSupport style)的操作日志:
$ git log --since=2.months.ago --until=1.day.ago
$ git show 12a86bc38 # By revision
$ git show v1.0.1 # By tag
$ git show feature132 # By branch name
$ git show 12a86bc38^ # Parent of a commit
$ git show 12a86bc38~2 # Grandparent of a commit
$ git show feature132@{yesterday} # Time relative
$ git show feature132@{2.hours.ago} # Time relative
查看本地倉(cāng)庫(kù)未推送的修改日志:
$ git log origin/master..new
# [old]..[new] - everything you haven't pushed yet
直接回滾到本地倉(cāng)庫(kù)最近的版本:(若你的修改未提交過)
$ git reset HEAD lib/foo.rb
回滾到本地倉(cāng)庫(kù)最近的版本:(若你的修改提交過)
如果你要回滾到最后1次提交之前的版本:
$ git commit --amend
如果你要回滾前已提交屢次代碼:
$ git checkout feature132
$ git reset --hard HEAD~2
master提交了3次修改,現(xiàn)在希望將最近3次修改移動(dòng)分支experimental,并取消master分支最近3次的修改:
$ git branch experimental # Creates a pointer to the current master state
$ git reset --hard master~3 # Moves the master branch pointer back to 3 revisions ago
$ git checkout experimental
略.
略.
$ git reflog
$ git log -g # Same as above, but shows in 'log' format
$ # Generate a changelog of Release 132
$ git shortlog release/132 ^release/131
$ # Tag this as v1.0.1
$ git tag v1.0.1 release/132
$ git blame FILE
略.
$ git branch experimental SHA1_OF_HASH
上一篇 Android工程師級(jí)別