git:找到哪个合并到当前分支的brough提交 [英] git: finding which merge brough commit into the current branch
问题描述
通常我会执行以下操作:
git log --oneline --ancestry-path --merges< commit-of-interest> .. C
$ b $ <<感兴趣的提交>
并且 C
的祖先。 - merges
选项可进一步过滤结果列表以仅显示合并提交。
每个打印的合并都会转换为以下类别之一:
- 合并带来
<感兴趣的提交>
转入分支 - 合并将一个不同的分支带入已经有
<感兴趣的提交>
- 两个父分支已经有
<感兴趣的提交>
第一个类别是您感兴趣的类别。您通常可以通过查看提交主题行来确定合并的类别。从列表底部开始;最古老的合并最有可能在第一类。
技术上可以编写脚本来过滤掉第二和第三类合并(仅测试查看合并的第一个父级是否可以访问<感兴趣的提交>
),但我从未发现它是必要的。
如果您需要对提交历史进行更深入的研究,那么我建议您查看历史图表:
git log --oneline --graph --color --decorate \
--ancestry-path<感兴趣的提交> .. C
您也可以在 - boundary
中折腾,尽管有时也会增加很多噪音。您可以使用 gitk
,但不幸的是它绘制的图表没有以正确的顺序显示父项( gitk
可能会绘制一个合并与其左边第二个父元素之间的边; git log --graph
总是绘制右边的第二个父边。)
I have a number of branches, which are periodically merged, i.e. we can have A, which is merged into B, then B into C, then A into D and D into C, etc. Suppose I have a commit X, which I know was originally introduces in A, and then merged into C somehow (I can see it when I do git log C). Is there a way to find out which merge (which merge commit) brought the commit X into the branch C?
Usually I do something like the following:
git log --oneline --ancestry-path --merges <commit-of-interest>..C
The --ancestry-path
argument is the key here: it causes git to only show commits that are both a descendant of <commit-of-interest>
AND an ancestor of C
. The --merges
option filters the resulting list further to only show merge commits.
Each of the printed merges falls into one of the following categories:
- the merge brought
<commit-of-interest>
into a branch - the merge brought a different branch into a branch that already has
<commit-of-interest>
- both parent branches already had
<commit-of-interest>
The first category is the one you're interested in. You can usually tell which category the merge is in by looking at the commit subject line. Start at the bottom of the list; the oldest merges are the most likely to be in the first category.
It's technically possible to write a script to filter out merges in the second and third categories (just test to see if <commit-of-interest>
is reachable by the merge's first parent), but I've never found it to be necessary.
If you need to do a more in-depth study of the commit history then I recommend looking at the history graph:
git log --oneline --graph --color --decorate \
--ancestry-path <commit-of-interest>..C
You may want to toss in --boundary
too, although sometimes that adds too much noise. You could use gitk
, but unfortunately the graph it draws doesn't show parentage in the correct order (gitk
might draw the edge between a merge and its second parent on the left; git log --graph
always draws the second parent edge on the right).
这篇关于git:找到哪个合并到当前分支的brough提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!