2011-05-31 32 views

回答

26

如果你想看到每犯上次合并合并,你可以尝试:

git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary 

这是我当前的日志的例子:

$ git log --graph --pretty=oneline --abbrev-commit 
* 44899b9 pouf 
* 8f49f9c Merge branch 'test' 
|\ 
| * 3db39ca test 
* | 69f431c pif 
* | df1f51c lala 
|/ 
* 8fae178 pif2 
* 20f8ba6 init 

如果我只想提交相关到最后的合并,我必须使用git log -1 --merges --pretty=format:%P这给了我第一次合并的父母可用:

$ git log -1 --merges --pretty=format:%P 
69f431cec7859b61d33c7503c9431ceea2aaf3e0 3db39ca3ab1e8f70462db23d94590628b5e7ad7b 

现在我知道我需要跟踪,我需要他们共同的基础,我可以通过git merge-base --octopus获得(--octopus有以防万一),父母:

$ git merge-base --octopus $(git log -1 --merges --pretty=format:%P) 
8fae178666e34a480b22e40f858efd9e7c66c3ca 
git log

现在我可以搜索,因为每一个承诺该基地目前HEAD就万事大吉了:

$ git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary --graph --pretty=oneline --abbrev-commit 
* 44899b9 pouf 
* 8f49f9c Merge branch 'test' 
|\ 
| * 3db39ca test 
* | 69f431c pif 
* | df1f51c lala 
|/ 
o 8fae178 pif2 

如果你是一个完美主义者一点你也可以这样做:

$ git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P))..$(git log -1 --merges --pretty=format:%H) --boundary --graph --pretty=oneline --abbrev-commit 
* 8f49f9c Merge branch 'test' 
|\ 
| * 3db39ca test 
* | 69f431c pif 
* | df1f51c lala 
|/ 
o 8fae178 pif2 

ñ嗷嗷,我想我会记住这是一个别名:)

PS:很明显,你不必保持--graph --pretty=oneline --abbrev-commit选项


资源:

1

如果您有合并提交(说a2345)并且说git log -1 a2345,它会告诉您父母的名称(即在此提交中合并的提交)。那是你在找什么?

+0

没错,这就是我想要的(尽管只显示1个提交)。我认为你可以为正常的git日志视图做到这一点? – 2011-05-31 17:27:23

+0

是的。如果你想浏览大量提交的父母,GUI(gitk)更有用。对单次提交的限制是因为'-1'。放下它,你会得到常规的日志。 – 2011-05-31 17:43:14

+0

如果我放下'-1'它显示所有提交消息的所有日志,这似乎没有用 – knocte 2017-02-27 04:28:46

36

说你的合并提交为ab2f8173git log ab2f8173^..ab2f8173将显示它在合并的提交

这里是如何变成一个git别名这便于再利用:

$ git config --global alias.merge-log '!f() { git log --stat "$1^..$1"; }; f' 
$ git merge-log 0865c12