Created
May 1, 2016 15:43
-
-
Save kapcod/3c49586b631eb1bf4f56d99f7f8da9e1 to your computer and use it in GitHub Desktop.
Finds git commit that merged other commit into master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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