你问的,所以在这里。
我用过这个剧本,但都很脆弱。把它当作灵感,而不是合理的解决办法。
它从的输出中提取(日期/作者/提交消息/修补程序)
git log -p
然后运行
patch
+
git add
+
git apply
对于所有人,按相反的顺序。
可能有某种方法可以自动找出正确的
patch_level
但是我没有打扰。并将作者传递给
GIT应用
如果不是所有的你。
#!/usr/bin/env ruby
class String
def shell_escape
if empty?
"''"
elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ self
self
else
result = ''
scan(/('+)|[^']+/) {
if $1
result << %q{\'} * $1.length
else
result << "'#{$&}'"
end
}
result
end
end
end
dir1, dir2, *files = ARGV
patchlog = Dir.chdir(dir1){`git log -p #{files.map(&:shell_escape).join(" ")}`}
patches = []
patchlog.each_line{|line|
if line =~ /\Acommit/
patches << {}
elsif line =~ /\A(Author|Date):\s*(.*)/
patches[-1][$1] = $2
elsif patches[-1][:diff].nil? and line !~ /\Adiff/
(patches[-1][:msg] ||= "") << line
else
(patches[-1][:diff] ||= "") << line
end
}
patch_level = 2
skip = 0
dry_run = false
patches.reverse[skip..-1].each{|patch|
author = patch["Author"].strip
date = patch["Date"].strip
msg = patch[:msg].strip
diff = patch[:diff]
if dry_run
puts ["git", "commit", "-m", msg, "--date", date].join(" ")
next
end
Dir.chdir(dir2){
IO.popen("patch -p#{patch_level}", "w"){|fh|
fh.puts diff
}
system "git", "add", *files
system "git", "commit", "-m", msg, "--date", date
}
}