git 修复后如何应用被拒绝的帅哥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17879746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I apply rejected hunks after fixing them?
提问by eckes
I'm trying to apply a patch to a file using git apply
. The overall patch failed, so I used git apply --reject
.
我正在尝试使用git apply
. 整体补丁失败,所以我使用了git apply --reject
.
Inspecting the generated .rej
file showed me what's wrong, now I fixed the problem in the .rej
file.
检查生成的.rej
文件告诉我出了什么问题,现在我修复了.rej
文件中的问题。
But trying to apply the .rej
file fails with message
但是尝试应用.rej
文件失败并显示消息
fatal: patch fragment without header at line 2: ...
致命:第 2 行没有标题的补丁片段:...
Is there a way to re-apply the .rej
file after fixing the problems there?Or do I have to modify the original patch and have to re-run git apply
?
有没有办法.rej
在修复那里的问题后重新应用文件?还是我必须修改原始补丁并重新运行git apply
?
This would be a bit cumbersome in that case since the original patch contains patches for dozens of files and I don't want to git checkout
the applied modifications in order to re-git apply
the whole fixed patch file.
在那种情况下这会有点麻烦,因为原始补丁包含数十个文件的补丁,我不想git checkout
应用修改来重新git apply
修复整个固定补丁文件。
采纳答案by drzaus
To clarify what @julian-squires said, the problem is that the .rej
files are missing some minor stuff between diff a/thefile...
and @@ -line/columns...
.
为了澄清@julian-squires 所说的内容,问题在于.rej
文件在diff a/thefile...
和之间缺少一些小东西@@ -line/columns...
。
ORIGINAL .rej
file
原始.rej
文件
diff a/the/original/file.cs b/the/original/file.cs (rejected hunks) @@ -27,9 +27,9 @@ whatever was on that line
diff a/the/original/file.cs b/the/original/file.cs (rejected hunks) @@ -27,9 +27,9 @@ whatever was on that line
You need to copy the a/b filenames from the diff
line and add them with the change indicators below, like:
您需要从该diff
行复制 a/b 文件名,并使用以下更改指示符添加它们,例如:
UPDATED .rej
file
更新.rej
文件
diff a/the/original/file.cs b/the/original/file.cs (rejected hunks) --- a/the/original/file.cs +++ b/the/original/file.cs @@ -27,9 +27,9 @@ whatever was on that line
diff a/the/original/file.cs b/the/original/file.cs (rejected hunks) --- a/the/original/file.cs +++ b/the/original/file.cs @@ -27,9 +27,9 @@ whatever was on that line
Then you can apply the .rej
files like a regular patch.
然后您可以.rej
像应用常规补丁一样应用这些文件。
回答by Julian Squires
I had this problem recently, while using git am --reject
to apply a bunch of patches. The way I approached it was to massage the .rej
file header into something patch(1)
would recognize, with
我最近遇到了这个问题,同时git am --reject
用来应用一堆补丁。我处理它的方法是将.rej
文件头按摩成patch(1)
可以识别的东西,用
sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \n+++ /'
and modified them with emacs (whose diff-mode
will update the line counts in the hunks as you modify the patch) and applied them with patch
.
并用 emacs 修改它们(diff-mode
当你修改补丁时,它会更新大块中的行数)并用patch
.
My workflow ended up looking like this:
我的工作流程最终看起来像这样:
$ (for i in $(find . -name \*.rej); do
sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \n+++ /' -i $i &&
emacsclient $i &&
patch -p0 < $i;
done) && git add -u && git clean -xdf && git am --continue
with suitable macros setup in emacs for the recurring cases. Not the most elegant approach, but it worked.
在 emacs 中为重复出现的情况设置合适的宏。不是最优雅的方法,但它奏效了。
回答by cforbish
There is no way around having to manually modify the files where there is a .rej
file. You said that you did fix this. Once all of the .rej
issues have been taken care of you are ready for git commit
. git apply --reject
still saves a little time in that git apply --reject
will modify files where it can.
没有办法在有文件的地方手动修改.rej
文件。你说你确实解决了这个问题。一旦所有.rej
问题都得到解决,您就可以开始了git commit
。 git apply --reject
仍然可以节省一点时间,git apply --reject
因为它可以修改文件。