想象一下下面的历史:

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

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


当前回答

图形化的解决方案是在gitk中找到它(使用“SHA1 ID”框),然后沿着提交行直到合并提交。

其他回答

我不得不这样做了好几次(感谢每个回答这个问题的人!),最后写了一个脚本(使用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"

图形化的解决方案是在gitk中找到它(使用“SHA1 ID”框),然后沿着提交行直到合并提交。

我的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

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