Git 基础 - 查看提交历史

git log 有许多选项能够帮助你搜寻你所要找的提交, 接下来咱们介绍些最经常使用的。html

一个经常使用的选项是 -p,用来显示每次提交的内容差别。 你也能够加上 -2 来仅显示最近两次提交:git

$ git log -p -2  ##貌似有时候后面-2参数不用写,或者不起效果
 

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

diff --git a/Rakefile b/Rakefile
index a874b73..8f94139 100644
--- a/Rakefile
+++ b/Rakefile

该选项除了显示基本信息以外,还在附带了每次 commit 的变化。 当进行代码审查,或者快速浏览某个搭档提交的 commit 所带来的变化的时候,这个参数就很是有用了。 你也能够为 git log 附带一系列的总结性选项。 好比说,若是你想看到每次提交的简略的统计信息,你能够使用 --stat 选项:spa

$ git log --stat

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

 Rakefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git log --graph --oneline --decorate --all
 

图形化比较显示所有不一样的commit code

而后你能够根据状况查看不一样的两次commit的区别htm

git diff 4ac0a6733 4ac0a6733

 

git log --follow file   ##显示文件更新历史

--followblog

Continue listing the history of a file beyond renames (works only for a single file).ip

关于git diff 输出结果分析能够参考博文:ci

http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.htmlrem

git log 显示各个branch 提交历史

ll changes made by commits in the current branch but that are not in <upstream> are saved to a temporary area. This is the same set of commits that would be shown by git log <upstream>..HEAD; or by git log 'fork_point'..HEAD, if --fork-point is active (see the description on --fork-point below); or by git log HEAD, if the --root option is specified.get

如上是英文说明。

其实能够经过 

git log <upstream>..HEAD 

将不一样的branch联合显示。

另外想查看一个branch的提交历史能够查看

git log branch-name

参考博文:

https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%AB%98%E7%BA%A7%E5%90%88%E5%B9%B6#_manual_remerge

https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2