Add this to your ~/.gitconfig
:
[alias]
find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n "$merge" ] && git show $merge'"
Then you can use the aliases like this:
# current branch
git find-merge <SHA-1>
# specify master
git find-merge <SHA-1> master
To see the merge commit's message and other details, use git show-merge
with the same arguments.
(Based on Gauthier's answer. Thanks to Rosen Matev and javabrett for correcting a problem with sort
.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…