假设,我有类似的git历史记录:
sha_001 'Some commit description'
sha_002 'Some other commit description (without regularity)'
sha_003 'Some other commit description (without regularity)'
sha_004 'Some other commit description (without regularity)'
sha_005 'Some other commit description (without regularity)'
sha_006 'Some other commit description (without regularity)'
如何为指定的提交创建补丁?
我知道:
git diff sha_003..sha_001
但这是针对提交范围的。我需要一些东西,比如:
git diff sha_002,sha_005,sha_006
在RubyMine中,我可以这样做:
但是
另外,我写了这个脚本:
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'tempfile'
abort "Usage:\ndiffco hash1,hash2,hash3" if ARGV.empty?
commits = ARGV.first.split ','
patch = ''
commits.each do |commit|
commit_data = <<-SEPARATOR
----------------------------------------------------------------------
----------------------------------------------------------------------
------------------ PATCH FOR COMMIT: #{commit} -----------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
SEPARATOR
commit_data += `git show #{commit} --stat`
commit_data += `git show #{commit} --unified=20`
patch += commit_data
end
path = File.join Dir::Tmpname.tmpdir, Dir::Tmpname.make_tmpname('commits', '.diff')
File.open(path, 'w') { |f| f.write patch }
`atom -a #{path}`
它允许我在Atom编辑器中看到单个diff / patch文件,但我不想看到中间变化的东西。
答案 0 :(得分:2)
我不认为,这可以直接使用git-diff。但是你可以做一个交互式的rebase来将指定的提交压缩在一起git rebase -i sha_006^
。然后你可以在rebase创建的新提交上使用git-diff。如果您不想丢失初始提交,只需在新的临时分支中运行rebase。
答案 1 :(得分:0)
git format-patch -o patches sha_006..sha_001
将为每个提交创建从sha_006到sha_001的补丁文件,并将所有这些补丁文件保存到补丁文件夹。