第六课 Git 日志
内容提要:浏览项目历史,查询指定提交内容,图形化显示分枝和合并...
'git log'是git中最常用的一个命令,执行之后,会显示该项目的提交历史。如果命令不加任何参数,那么就会显示目前所在分枝上,从最后一次提交开始,按时间顺序依次向前排列的所有提交历史记录。
$ git log
commit 166ae0c4d3f420721acbb115cc33848dfcc2121a
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
commit 166ae0c4d3f420721acbb115cc33848dfcc2121a
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
started write support
commit 9fceb02d0ae598e95dc970b74767f19372d61af8
Author: Magnus Chacon < [email protected] >
Date: Sun Apr 27 20:43:35 2008 -0700
Author: Magnus Chacon < [email protected] >
Date: Sun Apr 27 20:43:35 2008 -0700
updated rakefile
commit 964f16d36dfccde844893cac5b347e7b3d44abbc
Author: Magnus Chacon < [email protected] >
Date: Sun Apr 27 20:34:23 2008 -0700
Author: Magnus Chacon < [email protected] >
Date: Sun Apr 27 20:34:23 2008 -0700
commit the todo
上面显示了3次提交,对于每一次的提交都会显示四方面内容,分别是:
*提交的校验和
*作者信息(作者名和email地址)
*提交日期
*提交信息
*作者信息(作者名和email地址)
*提交日期
*提交信息
这是git日志默认输出的提交历史的内容格式。多数情况下,这样输出还是比较完美的。然而,有时候你只是想看到某个分枝上的最后几条提交信息,或者某些感兴趣的数据,只要在'git log'命令后面加上相应的参数,它就可以做更多有意义的事情。
日志输出格式
通过'git log'命令还能有很多种可选的输出格式。
显示补丁
你可以查看每一次提交条目的补丁内容,只需要在'git log'后加上-p选项,这在代码复查时很管用--在合并到你的某个分枝之前查看是其他作者提交了什么内容,或者是看看在最后发布之前所做的修改。
$ git log -p
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 18:29:31 2009 -0800
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 18:29:31 2009 -0800
added a commit function
diff --git a/lib/simplegit.rb b/lib/simplegit.rb
index dd6b7b3..c75a3e6 100644
--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -9,6 +9,10 @@ class SimpleGit
command("git status")
end
index dd6b7b3..c75a3e6 100644
--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -9,6 +9,10 @@ class SimpleGit
command("git status")
end
+ def commit(message)
+ command("git commit -m '#{message}'")
+ end
+
def show(treeish = 'master')
command("git show #{treeish}")
end
+ command("git commit -m '#{message}'")
+ end
+
def show(treeish = 'master')
command("git show #{treeish}")
end
commit 166ae0c4d3f420721acbb115cc33848dfcc2121a
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
started write support
diff --git a/lib/simplegit.rb b/lib/simplegit.rb
index dd6b7b3..e7dfaa9 100644
--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -9,6 +9,10 @@ class SimpleGit
command("git status")
end
index dd6b7b3..e7dfaa9 100644
--- a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -9,6 +9,10 @@ class SimpleGit
command("git status")
end
+ def add(path)
+ command("git add #{path}")
+ end
+
def show(treeish = 'master')
command("git show #{treeish}")
end
+ command("git add #{path}")
+ end
+
def show(treeish = 'master')
command("git show #{treeish}")
end
内容相当的冗长,但是这些输出都是分页的,所以一旦你得到了你需要的信息,后面的提交内容就可以都跳过了。
查看统计数字
你可以通过执行'git log -stat'命令,来显示被修改文件的修改统计信息,添加或删除了多少行。
$ git log --stat
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 18:29:31 2009 -0800
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 18:29:31 2009 -0800
added a commit function
lib/simplegit.rb | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
1 files changed, 4 insertions(+), 0 deletions(-)
commit 166ae0c4d3f420721acbb115cc33848dfcc2121a
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
Author: Scott Chacon < [email protected] >
Date: Sun Feb 8 16:50:43 2009 -0800
started write support
lib/simplegit.rb | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
1 files changed, 4 insertions(+), 0 deletions(-)
调整显示格式
使用'git log --pretty=format'命令,可以将提交历史显示成你想要的格式。这里format的可选项包括:oneline,short,medium,full,fuller,email,raw。每种格式都有侧重的显示相关内容。
$ git log --pretty=raw
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
tree dbcff814ec9fbbd3487171a7eaca73cf0069ba53
parent 85211d1138cb91f25c0633d361ff5f6e00677bc5
author Scott Chacon < [email protected] > 1234146571 -0800
committer Scott Chacon < [email protected] > 1234146571 -0800
commit 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc
tree dbcff814ec9fbbd3487171a7eaca73cf0069ba53
parent 85211d1138cb91f25c0633d361ff5f6e00677bc5
author Scott Chacon < [email protected] > 1234146571 -0800
committer Scott Chacon < [email protected] > 1234146571 -0800
added a commit function
commit 166ae0c4d3f420721acbb115cc33848dfcc2121a
tree e67636948570e27a9c2bf2699ecafadf729c3efc
parent 9fceb02d0ae598e95dc970b74767f19372d61af8
author Scott Chacon < [email protected] > 1234140643 -0800
committer Scott Chacon < [email protected] > 1234140643 -0800
tree e67636948570e27a9c2bf2699ecafadf729c3efc
parent 9fceb02d0ae598e95dc970b74767f19372d61af8
author Scott Chacon < [email protected] > 1234140643 -0800
committer Scott Chacon < [email protected] > 1234140643 -0800
started write support
这里,最常用的一种格式是'oneline', 每一行表示一次提交,一行内容包括校验和与提交信息两项内容。这种显示格式可以很简洁的显示大量的提交信息。
$ git log --pretty=oneline
0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
自定义格式
如果你希望git输出自定义的提交信息,你可以使用这样的命令:git log --pretty=format:"(format)".可以在""内自定义字符串与Git变量相结合的显示格式,在输出时,git会自动的将变量的位置输出为所需内容。
$ git log --pretty=format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"
The author of 0b7434d was Scott Chacon, 18 hours ago
The title was >>added a commit function<<
The author of 0b7434d was Scott Chacon, 18 hours ago
The title was >>added a commit function<<
The author of 166ae0c was Scott Chacon, 20 hours ago
The title was >>started write support<<
The title was >>started write support<<
The author of 9fceb02 was Magnus Chacon, 10 months ago
The title was >>updated rakefile<<
The title was >>updated rakefile<<
The author of 964f16d was Magnus Chacon, 10 months ago
The title was >>commit the todo<<
The title was >>commit the todo<<
The author of 8a5cbc4 was Scott Chacon, 5 months ago
The title was >>updated readme<<
The title was >>updated readme<<
更多详细自定义格式方法可以参考 git log docs 。
分枝拓扑图
还有一个日志输出选项是-graph,这个选项与--pretty=oneline结合不仅可以显示提交历史而且还会显示图形化的分枝拓扑
$ git log --pretty=oneline --graph
* 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
|\
| * a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
* | 4a447f750f910445e38338aadef48f3038b35d2b sweet
|\ \
| |/
| * 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
* | 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
|\ \
| |/
| * 4682c3261057305bdd616e23b64b0857d832627b added a todo file
| * ebe0d698d3def0ec43f9b883857717de8c405d96 removed the todo file
| * 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
* | 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
* | 85211d1138cb91f25c0633d361ff5f6e00677bc5 removed todo file
|/
* 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
* 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
|\
| * a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
* | 4a447f750f910445e38338aadef48f3038b35d2b sweet
|\ \
| |/
| * 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
* | 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
|\ \
| |/
| * 4682c3261057305bdd616e23b64b0857d832627b added a todo file
| * ebe0d698d3def0ec43f9b883857717de8c405d96 removed the todo file
| * 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
* | 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
* | 85211d1138cb91f25c0633d361ff5f6e00677bc5 removed todo file
|/
* 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
提交查询过滤器
利用提交查询过滤器可以查询经过某些条件限制后得到的提交信息。
日期区间
'git log'命令后如果跟-before和-after选项,就会显示两个日期之间的提交条目。日期格式也有不同的可选格式。例如,我想查看1月26号之后,2个星期之前的提交内容,可以运行:
$ git log --before="2 weeks ago" --after="2009-01-26" --pretty=oneline
dfb047b9e4f7f66c5322ef642f21fd92b0a975e3 Mention "local convention" rule in t
25655221745fd27d5da3bda7ad0fe49f2005d776 Windows: Revert to default paths and
35fb0e8633217f602360a9987af51c4b960e7850 Compute prefix at runtime if RUNTIME
8e3462837b0ace04357503a3f58802cc2231df29 Modify setup_path() to only add git_
2fb3f6db96492b680899f9e40f434eeb4c778a84 Add calls to git_extract_argv0_path(
2cd72b0b290e40fb4d6a925ce26603503f01aa09 git_extract_argv0_path(): Move check
4dd47c3b867f51211d0dc4474dab0fee5ca614da Refactor git_set_argv0_path() to git
026fa0d5ad9538ca76838070861531c037d7b9ba Move computation of absolute paths f
dfb047b9e4f7f66c5322ef642f21fd92b0a975e3 Mention "local convention" rule in t
25655221745fd27d5da3bda7ad0fe49f2005d776 Windows: Revert to default paths and
35fb0e8633217f602360a9987af51c4b960e7850 Compute prefix at runtime if RUNTIME
8e3462837b0ace04357503a3f58802cc2231df29 Modify setup_path() to only add git_
2fb3f6db96492b680899f9e40f434eeb4c778a84 Add calls to git_extract_argv0_path(
2cd72b0b290e40fb4d6a925ce26603503f01aa09 git_extract_argv0_path(): Move check
4dd47c3b867f51211d0dc4474dab0fee5ca614da Refactor git_set_argv0_path() to git
026fa0d5ad9538ca76838070861531c037d7b9ba Move computation of absolute paths f
贡献者过滤器
git还可以通过贡献者过滤器来查看某个作者发起的提交。在commit对象中实际上存在两个人的记录--一个是作者(author),也就是做原始提交的人。第二个人名是提交者(committer),就是提交到仓库中的人。在这里找不到合适的翻译,所以把二者统称为
贡献者。一般情况下,所指的都是同一个人,但是在某些情况下就不是了--譬如,有一个作者将他写的东西email给项目持有人,这个项目持有人就是提交者(committer),项目持有人将作者提交的东西提交到git仓库中。
大多数情况搜索的是作者,当然你可以通过-author或者-committer加名字的方式来搜索相应的提交条目。下面这个例子我们是执行命令来查找作者名(author)为Johannes Schindelin,在过去两周内的所有提交条目:
$ git log --author=johannes.schindelin --since="14 days ago" --pretty=oneline
26be15f09db15d2b53a13d0f184d77fb54367f33 filter-branch: do not consider diver
e1e4389832f32bb6ce029d6a6b110aa9ec768ea8 apply: fix access to an uninitialize
418566b6fdcc0eb1b5549d0742366aa13a7ff277 Fix 'git diff --no-index' with a non
f7951e1d97aeb7b3ed359faeab5edf9e870ec8a5 Simplify t3412
37e5c8f46042510176a71d73c903c44214e09815 Simplify t3411
4bd03d15e495086a38470b59447296db4c235cb9 Simplify t3410
008849689e04e774aa7b194cd690405761e2383a test-lib.sh: introduce test_commit()
03af0870a0e6d551a31eb830d5c2682b82ae0ac6 lib-rebase.sh: Document what set_fak
29a03348a336f28025c824436a713cb9cb01b7a6 t3404 & t3411: undo copy&paste
b8469ad0578d6b84ec92752a5f8df3ca5828af77 test-path-utils: Fix off by one, fou
f265458f6116a0c03200477ae3b839f2a75bf0fa get_sha1_basic(): fix invalid memory
26be15f09db15d2b53a13d0f184d77fb54367f33 filter-branch: do not consider diver
e1e4389832f32bb6ce029d6a6b110aa9ec768ea8 apply: fix access to an uninitialize
418566b6fdcc0eb1b5549d0742366aa13a7ff277 Fix 'git diff --no-index' with a non
f7951e1d97aeb7b3ed359faeab5edf9e870ec8a5 Simplify t3412
37e5c8f46042510176a71d73c903c44214e09815 Simplify t3411
4bd03d15e495086a38470b59447296db4c235cb9 Simplify t3410
008849689e04e774aa7b194cd690405761e2383a test-lib.sh: introduce test_commit()
03af0870a0e6d551a31eb830d5c2682b82ae0ac6 lib-rebase.sh: Document what set_fak
29a03348a336f28025c824436a713cb9cb01b7a6 t3404 & t3411: undo copy&paste
b8469ad0578d6b84ec92752a5f8df3ca5828af77 test-path-utils: Fix off by one, fou
f265458f6116a0c03200477ae3b839f2a75bf0fa get_sha1_basic(): fix invalid memory
你可以指定完整人名或email地址来搜索,你也可以使用这些值的部分内容来查询,譬如,搜索Junio Hamano作者的提交内容,可以执行下面的任意一条语句:
$ git log --author=Junio
$ git log --author=Hamano
$ git log --author="Junio C Hamano"
$ git log
$ git log --author=Hamano
$ git log --author="Junio C Hamano"
$ git log
我们甚至还可以通过'gmail.com'来搜索,结果就是email主机地址为gmail.com的贡献者所作提交的内容。
$ git log --author=gmail --pretty=format:"%ae" | wc -l
1348
$ git log --author=gmail --pretty=format:"%ae" | sort -u | wc -l
113
1348
$ git log --author=gmail --pretty=format:"%ae" | sort -u | wc -l
113
从这两个命令执行之后的结果看到,Git源码项目有113个gmail账户的作者贡献的1348个补丁。有趣的是,没有一个作者使用hotmail账户,但是有81个补丁来自'.mil'(都出自一个人)。
$ git log --author='\.mil' --pretty=format:"%ae" | wc -l
81
81
查找提交信息
如果你对“提交信息”更感兴趣,你可以通过提交信息里面的某个字符串来查找相应的提交。例如,下面是搜索在提交信息中含有'c90'的所有提交内容。
$ git log --grep='C90' --pretty=oneline
8c9e7947c2a76fb21bda11816c544d50e271156d http-push.c: squelch C90 warnings.
8c9e7947c2a76fb21bda11816c544d50e271156d http-push.c: squelch C90 warnings.
文件历史
还有的时候,你希望查看某个指定文件的提交历史。譬如你希望查看'notes.c'文件每一次的提交历史,你可以运行:
$ git log --pretty=oneline -- notes.c
22a3d060937072b0f197a8084af879c753c68fe7 git-notes: fix printing of multi-lin
2dd625d022074bb677bdd5caa5146cabaf726123 Speed up git notes lookup
879ef2485d6ced20845ca626ecb45a9b65aa3a70 Introduce commit notes
22a3d060937072b0f197a8084af879c753c68fe7 git-notes: fix printing of multi-lin
2dd625d022074bb677bdd5caa5146cabaf726123 Speed up git notes lookup
879ef2485d6ced20845ca626ecb45a9b65aa3a70 Introduce commit notes
你还可以对文件目录进行这样的操作,譬如你想查看't/lib-httpd'目录的提交历史:
$ git log --pretty=oneline --all -- t/lib-httpd/
466ddf90c2f270b973d141f20e912f743743331c http-push: when making directories,
603fb1168218a813f1b0816b1208c5d0c92cf29d Avoid apache complaining about lack
faa4bc35a05ddb1822f3770cd8c51859e3b929ee http-push: add regression tests
466ddf90c2f270b973d141f20e912f743743331c http-push: when making directories,
603fb1168218a813f1b0816b1208c5d0c92cf29d Avoid apache complaining about lack
faa4bc35a05ddb1822f3770cd8c51859e3b929ee http-push: add regression tests
也可以加入多个查询项目,譬如要查看't/lib-httpd'目录或notes.c文件的提交历史:
$ git log --pretty=oneline -- t/lib-httpd/ notes.c
7b75b331f6744fbf953fe8913703378ef86a2189 Merge branch 'js/notes'
466ddf90c2f270b973d141f20e912f743743331c http-push: when making directories,
22a3d060937072b0f197a8084af879c753c68fe7 git-notes: fix printing of multi-lin
2dd625d022074bb677bdd5caa5146cabaf726123 Speed up git notes lookup
879ef2485d6ced20845ca626ecb45a9b65aa3a70 Introduce commit notes
603fb1168218a813f1b0816b1208c5d0c92cf29d Avoid apache complaining about lack
faa4bc35a05ddb1822f3770cd8c51859e3b929ee http-push: add regression tests
7b75b331f6744fbf953fe8913703378ef86a2189 Merge branch 'js/notes'
466ddf90c2f270b973d141f20e912f743743331c http-push: when making directories,
22a3d060937072b0f197a8084af879c753c68fe7 git-notes: fix printing of multi-lin
2dd625d022074bb677bdd5caa5146cabaf726123 Speed up git notes lookup
879ef2485d6ced20845ca626ecb45a9b65aa3a70 Introduce commit notes
603fb1168218a813f1b0816b1208c5d0c92cf29d Avoid apache complaining about lack
faa4bc35a05ddb1822f3770cd8c51859e3b929ee http-push: add regression tests
其他选项
很多时候想查看未合并的提交历史记录,所以你可以加上'--no-merges'选项
$ git log --grep='C90' --pretty=oneline --no-merges
8c9e7947c2a76fb21bda11816c544d50e271156d http-push.c: squelch C90 warnings.
8f1d2e6f49ee51ac062ab38337a6a70dd1998def [PATCH] Compilation: zero-length arr
01c6ad29bd1b647d4fd1acea54e374c740ec3c10 [PATCH] Fix strange timezone handlin
8c9e7947c2a76fb21bda11816c544d50e271156d http-push.c: squelch C90 warnings.
8f1d2e6f49ee51ac062ab38337a6a70dd1998def [PATCH] Compilation: zero-length arr
01c6ad29bd1b647d4fd1acea54e374c740ec3c10 [PATCH] Fix strange timezone handlin
还可以在查看日志命令最后加上-N来查看满足条件的最近的N条历史记录:
$ git log --pretty=oneline --no-merges -5
621f1b4bcf40f1469fc59202248df35619e33c82 GIT 1.6.2-rc0
7851386948dce72c739bcdfe08f069afe4f5ea45 emacs: Remove the no longer maintain
5a7b3bf5275adf86fdd23f8824562b88c8a20e33 git.el: Add some notes about Emacs v
6c4f70d5b2fb8f9275ca85e0927f00b8bc892819 git.el: Use integer instead of chara
efd49f50fc087df2ad46f194ca848c5335f4cca9 git.el: Set a regexp for paragraph-s
621f1b4bcf40f1469fc59202248df35619e33c82 GIT 1.6.2-rc0
7851386948dce72c739bcdfe08f069afe4f5ea45 emacs: Remove the no longer maintain
5a7b3bf5275adf86fdd23f8824562b88c8a20e33 git.el: Add some notes about Emacs v
6c4f70d5b2fb8f9275ca85e0927f00b8bc892819 git.el: Use integer instead of chara
efd49f50fc087df2ad46f194ca848c5335f4cca9 git.el: Set a regexp for paragraph-s
如果下面是我们的提交历史:
$ git log --pretty=oneline --graph
* 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
* 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
* 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
* a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
* 310154e3c7db47d8bac935c2c43aee6afac11aae updated README formatting and adde
* f7f3f6dd8fd3fa40f052427c32785a0fa01aaa5f changed my name a bit
* 710f0f8d2cdf5af87033b9ec08859a505f9a6af5 added ls-files
* c110d7ff8cfb86fd5cce9a8aee462678dbb4ef9b made the ls-tree function recursiv
* ce9b0d5551762048735dd67917046b44176317e0 limiting log to 30
* 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
* 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
* 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
* a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
* 310154e3c7db47d8bac935c2c43aee6afac11aae updated README formatting and adde
* f7f3f6dd8fd3fa40f052427c32785a0fa01aaa5f changed my name a bit
* 710f0f8d2cdf5af87033b9ec08859a505f9a6af5 added ls-files
* c110d7ff8cfb86fd5cce9a8aee462678dbb4ef9b made the ls-tree function recursiv
* ce9b0d5551762048735dd67917046b44176317e0 limiting log to 30
我们希望只看到提交信息为'added Is-files'之后,'updated readme'之前的提交历史,我们可以这样指定查询:
[master]$ git log --pretty=oneline 710f0f..8a5cbc
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
310154e3c7db47d8bac935c2c43aee6afac11aae updated README formatting and added
f7f3f6dd8fd3fa40f052427c32785a0fa01aaa5f changed my name a bit
8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
a5f4a0daa9b13bb85283461ddaba6e589e34ccb5 added cat-file
310154e3c7db47d8bac935c2c43aee6afac11aae updated README formatting and added
f7f3f6dd8fd3fa40f052427c32785a0fa01aaa5f changed my name a bit
如果你在查找一个分枝上的提交时,这样做非常管用。譬如,你目前在'master'分枝上,并且想查看'experiment'分枝上还没有合并的提交记录的话,可以这样:
$ git log master..experiment --pretty=oneline
f6b98e46bdf64454d7c6ab76d617237118799d7b git-web--browse: Fix check for /bin/
df487baa30924a36ade38ada4f77379236dcce0f Merge branch 'maint'
a9ee90d7ff9f3854b3096b4abbdc2013708704f5 completion: Get rid of tabbed indent
cf9957875c3a27b6ae4593e1fa9d4dabbde68433 completion: Fix GIT_PS1_SHOWDIRTYSTA
7e1100e9e939c9178b2aa3969349e9e8d34488bf gitweb: add $prevent_xss option to p
f6b98e46bdf64454d7c6ab76d617237118799d7b git-web--browse: Fix check for /bin/
df487baa30924a36ade38ada4f77379236dcce0f Merge branch 'maint'
a9ee90d7ff9f3854b3096b4abbdc2013708704f5 completion: Get rid of tabbed indent
cf9957875c3a27b6ae4593e1fa9d4dabbde68433 completion: Fix GIT_PS1_SHOWDIRTYSTA
7e1100e9e939c9178b2aa3969349e9e8d34488bf gitweb: add $prevent_xss option to p
这就告诉你,如果现在合并的话,那么所有列出的这些提交都会被合并。你也可以不写某一端的分枝名,git会判断你目前正在哪个分枝上,所以,如果你在master分枝上的话,下面的命令执行结果和上面的一样:
$ git log ..experiment --pretty=oneline
如果你在experiment分枝上,也想看到相同的信息,即还没有合并到master的提交,可以运行:
$ git log master.. --pretty=oneline
这一节讲的都是很常用的命令,下一课将深入剖析这些内容,但是这一节课最关键的是记住这些命令和它的作用。