Skip to content

Instantly share code, notes, and snippets.

@derekkraan
Created August 26, 2013 12:19
Show Gist options
  • Save derekkraan/6340863 to your computer and use it in GitHub Desktop.
Save derekkraan/6340863 to your computer and use it in GitHub Desktop.
Cherry pick unique commits from a branch onto another branch. Useful if you've merged master into your branch and then rebased your branch on master. That can be a clusterfuck if git doesn't recognize the commits that you merged in from master anymore.
hashes = ["41ae018", "610f707", "7cd4577", "7d8de28", "df6a0d6", "891e049", "45e6aff", "5546b80", "12df477", "674b60f", "9b04f92", "77e00b7", "b5525c7", "a0cda26", "ec974af", "31ce76c", "e5166d1", "4ff48a4", "1db308b", "efed886", "c0b1984", "8ddc684", "406fa59", "9a68945", "fb70cb1", "2bf804d", "3caef0c", "e12d122", "f3afee3", "e0acb79", "98580dc", "5e80380", "ca59dc6", "d16a9a4", "d416a98", "2d73dd8", "57cd6b1", "438ea0a", "a32f919", "35abe8d"]
current_hash = if ARGV.first.nil?
`git log --pretty=format:'%h' -n 1`
else
ARGV.first
end
current_index = hashes.index(current_hash)
if current_index
hashes.slice!(0, current_index + 1)
end
hashes.each do |hash|
puts "> git cherry-pick #{hash}"
exit unless system "git cherry-pick #{hash}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment