如果将
my-feature-branch
合并到my-main-branch
,我该如何查看从my-feature-branch
合并了哪些提交记录?my-feature-branch
合并到my-main-branch
,我该如何查看从my-feature-branch
合并了哪些提交记录?git log abc123^..abc123
显示已经合并到合并提交abc123
的提交。
创建一个git
别名log-merge
以便轻松重用:
$ git config --global alias.log-merge \
'!f() { git log --stat "$1^..$1"; }; f'
$ git log-merge abc123
对于一行代码版本:
$ git config --global alias.log-merge-short \
'!f() { git log --pretty=oneline "$1^..$1"; }; f'
如果你想查看最近一次合并中合并的每个提交,可以尝试以下方法:
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
现在我想将其保留为别名 :)
--graph --pretty=oneline --abbrev-commit
选项是可选的。
资源:
git log --graph --oneline
是 git log --graph --pretty=oneline --abbrev-commit
的快捷方式。 - Tal Jacob - Sir Jacques--boundary
,那么我会得到相同的数字,但我不知道为什么,因为我不完全理解涉及的所有部分。 - bmaupin如果你有一个合并提交(比如 a2345
),然后运行 git log -1 a2345
,它会告诉你父提交的名称(即被合并到此提交中的提交)。这是你要找的吗?
-1
。去掉它,您将得到常规日志。 - Noufal Ibrahim
`$ git config --global alias.merge-log-short '!f() { git log --pretty=oneline "$1^..$1"; }; f'`
- glade