[英]determining which merge commit caused a specific commit to be merged into my branch
Given the following history: 鉴于以下历史:
master A-B-C-D-E-F
\
topic G-H-I
What git command can I use to determine that C
caused G
to be merged into master
? 我可以用什么git命令来确定C
导致G
合并为master
?
Said another way, ignoring the branch name: "How can I determine which merge commit caused A to have G in its ancestry?" 换句话说,忽略分支名称:“我怎样才能确定哪个合并提交导致A在其祖先中有G?”
git merge-base G master
gives the common ancestor: git merge-base G master
给出了共同的祖先:
Find common ancestor of two git branches 找到两个git分支的共同祖先
I think this answers your first formulation, but I may not understand what you mean when you say " C
caused G
to be merged into master
". 我认为这回答了你的第一个表述,但当你说“ C
导致G
被合并master
”时,我可能不明白你的意思。
You can walk forward in time from the first commit until you hit a merge commit that can reach the sought-after commit. 您可以从第一次提交开始,直到达到可以达到广受欢迎的提交的合并提交。 By making the walk a first-parent walk we ignore all commits happening in side-branches. 通过使步行成为第一父步行,我们忽略了在分支中发生的所有提交。
Using the reachability test described in How can I tell if one commit is a descendant of another commit? 使用在如何判断一个提交是否是另一个提交的后代中描述的可访问性测试? , the following example finds the first merge commit that introduced the commit identified by the contents of the wanted
environment variable to the master branch: ,以下示例查找第一个合并提交,该提交将wanted
环境变量的内容标识的提交引入主分支:
for c in $(git rev-list --reverse --first-parent --merges master) ; do
test $(git merge-base $wanted $c) = $wanted && echo $c && break
done
For Git 1.8.0 and later, the new --is-ancestor
option can shorten the command somewhat: 对于Git 1.8.0及更高版本,新的--is-ancestor
选项可以稍微缩短命令:
for c in $(git rev-list --reverse --first-parent --merges master) ; do
git merge-base --is-ancestor $wanted $c && echo $c && break
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.