想象一下下面的历史:

       c---e---g--- feature
      /         \
-a---b---d---f---h--- master

我怎么能找到当提交“c”已合并到主(即,找到合并提交“h”)?


当前回答

我不得不这样做了好几次(感谢每个回答这个问题的人!),最后写了一个脚本(使用Gauthier的方法),可以将它添加到我的git实用程序的小集合中。你可以在这里找到它:https://github.com/mwoehlke/git-utils/blob/master/bin/git-merge-point。

其他回答

这是在master中找到commit的最好方法:

[alias]
    find-merge = !"f() { git rev-list $1..master --ancestry-path --merges --reverse | head -1; }; f"

我需要这样做,并以某种方式找到了git-when-merged(它实际上引用了这个SO问题,但Michael Haggerty从未在这里添加对他非常出色的Python脚本的引用)。现在我有了。

对于Ruby人群来说,有git- where。非常容易。

$ gem install git-whence
$ git whence 1234567
234557 Merge pull request #203 from branch/pathway
git log --topo-order

然后在提交之前寻找第一个合并。

我的ruby版本的@robinst的想法,工作速度快了两倍(这在搜索非常旧的提交时很重要)。

find-commit.rb

commit = ARGV[0]
master = ARGV[1] || 'origin/master'

unless commit
  puts "Usage: find-commit.rb commit [master-branch]"
  puts "Will show commit that merged <commit> into <master-branch>"
  exit 1
end

parents = `git rev-list #{commit}..#{master} --reverse --first-parent --merges`.split("\n")
ancestry = `git rev-list #{commit}..#{master} --reverse --ancestry-path --merges`.split("\n")
merge = (parents & ancestry)[0]

if merge
  system "git show #{merge}"
else
  puts "#{master} doesn't include #{commit}"
  exit 2
end

你可以这样使用它:

ruby find-commit.rb SHA master