brainopia (owner)

Revisions

gist: 184326 Download_button fork
public
Public Clone URL: git://gist.github.com/184326.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
 
# Usually you want to stick with git rebase --onto, but if you have conflicts, you can use this script instead
 
raise 'You need to specify a commit' unless ARGV.first
 
commit = ARGV.first
following_commits = `git rev-list #{commit}..`.split.reverse
 
def info(commit, format)
  `git show --format="#{format}" #{commit}`.split("\n").first
end
 
def description_of(commit)
  info(commit, "%s")[0...80]
end
 
def parents_of(commit)
  info(commit, "%p").split
end
 
puts `git reset --hard #{commit}~1`
 
following_commits.each do |commit|
  parents = parents_of commit
  if parents.size > 1
    puts "Commit '#{description_of commit}' has multiple parents:"
    parents.each {|it| puts "#{it} #{description_of it}" }
    puts "Choose which one do you want to use:"
    parent_number = STDIN.gets.strip
    puts `git cherry-pick -m #{parent_number} #{commit}`
  else
    puts `git cherry-pick #{commit}`
  end
end