译者:zhanhailiang 日期:2015-01⑵1
原文链接:25 Tips for Intermediate Git Users
抛弃暂存区的所有操作:
$ 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
通过搜索提交的注释关键字过滤日志:
$ git log --grep="Something in the message"
查询指定文件的修改日志:
$ git log lib/foo.rb
查看分支feature/132与分支feature/145,其各自与master分支的区分:
$ git log feature/132 feature/145 ^master
也能够查询指定时间段内(该时间格式支持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
查看本地仓库未推送的修改日志:
$ git log origin/master..new
# [old]..[new] - everything you haven't pushed yet
直接回滚到本地仓库最近的版本:(若你的修改未提交过)
$ git reset HEAD lib/foo.rb
回滚到本地仓库最近的版本:(若你的修改提交过)
如果你要回滚到最后1次提交之前的版本:
$ git commit --amend
如果你要回滚前已提交屡次代码:
$ git checkout feature132
$ git reset --hard HEAD~2
master提交了3次修改,现在希望将最近3次修改移动分支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工程师级别
下一篇 timensten 常见维护操作