显示先前 git 合并中涉及的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6191138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show commits involved in a prior git merge
提问by The Pixel Developer
Say I create a hotfix
branch off of a develop
branch, make two commits, merge this back to the develop
branch, and destroy the hotfix
branch.
假设我hotfix
从一个develop
分支创建一个分支,进行两次提交,将其合并回develop
分支,然后销毁该hotfix
分支。
How do I find out what commits were part of the merge? Is that possible?
我如何找出哪些提交是合并的一部分?那可能吗?
采纳答案by Colin Hebert
If you want to see every commits merged in the last merge you can try that :
如果您想查看上次合并中合并的每个提交,您可以尝试:
git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary
Here is an example of my current log :
这是我当前日志的示例:
$ git log --graph --pretty=oneline --abbrev-commit
* 44899b9 pouf
* 8f49f9c Merge branch 'test'
|\
| * 3db39ca test
* | 69f431c pif
* | df1f51c lala
|/
* 8fae178 pif2
* 20f8ba6 init
If I only want commits related to the last merge I have to use git log -1 --merges --pretty=format:%P
which gives me the parents of the first merge available :
如果我只想要与上次合并相关的提交,我必须使用git log -1 --merges --pretty=format:%P
它给我第一个可用合并的父级:
$ git log -1 --merges --pretty=format:%P
69f431cec7859b61d33c7503c9431ceea2aaf3e0 3db39ca3ab1e8f70462db23d94590628b5e7ad7b
Now that I know which parents I need to track, I need their common base that I can obtain through git merge-base --octopus
(--octopus is there just in case) :
现在我知道我需要跟踪哪些父母,我需要他们的共同基础,我可以通过git merge-base --octopus
(--章鱼在那里以防万一):
$ git merge-base --octopus $(git log -1 --merges --pretty=format:%P)
8fae178666e34a480b22e40f858efd9e7c66c3ca
Now with git log
I can search every commit since the base to the current HEAD and voilà :
现在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
If you're a bit perfectionist you can also do this :
如果你有点完美主义者,你也可以这样做:
$ 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
Now I think I'll keep this as an alias :)
现在我想我会把它作为别名:)
PS: Obviously you don't have to keep the --graph --pretty=oneline --abbrev-commit
options
PS:显然你不必保留--graph --pretty=oneline --abbrev-commit
选项
Resources :
资源 :
回答by Jesse
Say your merge commit is ab2f8173
, git log ab2f8173^..ab2f8173
will show the commits which it merged in.
假设您的合并提交是ab2f8173
,git log ab2f8173^..ab2f8173
将显示它合并的提交。
Here is how to turn this into a git
alias for easy re-use:
以下是如何将其转换为git
别名以便于重用:
$ git config --global alias.merge-log '!f() { git log --stat "^.."; }; f'
$ git merge-log 0865c12
回答by Noufal Ibrahim
If you have a merge commit (say a2345
) and say git log -1 a2345
, it will tell you the names of the parents (i.e. the commits which got merged in this commit). Is that what you're looking for?
如果你有一个合并提交(比如a2345
)和 say git log -1 a2345
,它会告诉你父母的名字(即在这个提交中合并的提交)。这就是你要找的吗?