Skip to content

Instantly share code, notes, and snippets.

@kapcod
Created May 1, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapcod/3c49586b631eb1bf4f56d99f7f8da9e1 to your computer and use it in GitHub Desktop.
Save kapcod/3c49586b631eb1bf4f56d99f7f8da9e1 to your computer and use it in GitHub Desktop.
Finds git commit that merged other commit into master
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment