git:找到哪个合并到当前分支的brough提交 [英] git: finding which merge brough commit into the current branch

查看:151
本文介绍了git:找到哪个合并到当前分支的brough提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多分支,它们会定期合并,也就是说,我们可以将A合并到B中,然后将B合并到C中,然后将A合并到D中,并将D合并到C中等等。假设我有一个提交X,我知道最初是在A中引入的,然后以某种方式合并到C中(我可以在做git日志C时看到它)。有没有办法找出哪个合并(合并提交)将提交X带入分支C?

解决方案

通常我会执行以下操作:

  git log --oneline --ancestry-path --merges< commit-of-interest> .. C 


$ b $ < - 祖先路径参数是这里的关键:它使git仅显示既是后代<感兴趣的提交> 并且 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆