显示先前git合并中涉及的提交

问题描述 投票:45回答:3

假设我从hotfix分支创建一个develop分支,进行两次提交,将其合并回develop分支,并销毁hotfix分支。

我如何找出哪些提交是合并的一部分?那可能吗?

git merge branch commit
3个回答
35
投票

如果要查看上次合并中合并的每个提交,可以尝试:

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获得的共同基础( - 以及以防万一):

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

现在使用git log我可以搜索从基数到当前HEAD的所有提交和voilà:

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


资源:


52
投票

假设您的合并提交是ab2f8173git log ab2f8173^..ab2f8173将显示它合并的提交。

以下是如何将其转换为git别名以便于重复使用:

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

1
投票

如果你有一个合并提交(比如a2345)并说git log -1 a2345,它会告诉你父母的名字(即在这次提交中合并的提交)。这就是你要找的东西吗?

© www.soinside.com 2019 - 2024. All rights reserved.