背景:this question。git apply <patchfile>只是重新创建文件,而不提交历史记录,这在本例中是可取的。git-apply有什么开关可以做到这一点吗?或者,有没有办法将补丁文件转换为git-am兼容文件?(目前,git-am会报错"Patch format detection“)
发布于 2010-07-10 01:32:21
你问过了,所以就是这样。
我使用了这个脚本,但它非常脆弱。把它当作一种灵感,而不是一个合理的解决方案。
它从git log -p的输出中提取(日期/作者/提交消息/补丁),然后以相反的顺序为所有人运行patch+git add+git apply。
可能有一些方法可以自动找出正确的patch_level,但我并没有费心。如果不是你,就把author传给git apply。
#!/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
}
}发布于 2011-09-06 21:58:27
调查一下git quiltimport。您提供了一个目录,该命令在该目录中查找名为"series“的文件。在这个文件中,你只需简单地提到补丁文件的名称,按照它应用它们的顺序。文件中实际差异之前的文本被用作提交注释,文件名(减去.patch)被用作标题,并且它试图在每个补丁中找到作者,如果没有找到,就会要求你提供它。
https://stackoverflow.com/questions/3194240
复制相似问题