现在的位置: 首页 > 综合 > 正文

[翻译]中级Git用户的25个使用技巧(下)

2018年04月08日 ⁄ 综合 ⁄ 共 1752字 ⁄ 字号 评论关闭
译者:zhanhailiang 日期:2015-01-21

原文链接:25 Tips for Intermediate Git Users

存储内容到Stashes, Index和文件系统

10. 暂存区

丢弃暂存区的所有操作:

$ git stash
# Do something...
$ git stash pop

11. 交互式添加修改到暂存区

$ 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>  

12. Storing/Retrieving from the File System

略.

查看git日志

13. 查看操作日志

查看最近提交的操作日志:

$ git log -p

只查看最近修改的文件列表:

$ git log --stat

14. 搜索日志

查询指定作者的更新日志:

$ 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

15. 查看指定版本的相关信息

$ 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

16. Selecting a Range

查看本地仓库未推送的修改日志:

$ git log origin/master..new
# [old]..[new] - everything you haven't pushed yet

回滚与错误修复

17. 回滚修改

直接回滚到本地仓库最近的版本:(若你的修改未提交过)

$ git reset HEAD lib/foo.rb

回滚到本地仓库最近的版本:(若你的修改提交过)

如果你要回滚到最后一次提交之前的版本:

$ git commit --amend

如果你要回滚前已经提交多次代码:

$ git checkout feature132

$ git reset --hard HEAD~2

18. 分支操作

master提交了三次修改,现在希望将最近三次修改移动分支experimental,并取消master分支最近三次的修改:

$ 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

19. Interactive Rebasing

略.

20. Cleaning Up

略.

其它注意事项

21. 查看上次查询的SHA-1记录日志

$ git reflog
$ git log -g # Same as above, but shows in 'log' format

22. 分支命名

$ # 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

23. 查询指定文件的各行编辑日志

$ git blame FILE

24. Database Maintenance

略.

25. 重建一个已丢失败的分支

$ git branch experimental SHA1_OF_HASH

抱歉!评论已关闭.