21

を使用してファイルにパッチを適用しようとしていますgit apply。全体的なパッチが失敗したので、使用しgit apply --rejectました。

生成された.rejファイルを調べると、何が問題なのかがわかったので、ファイルの問題を修正しました.rej

しかし、.rejファイルを適用しようとすると、メッセージで失敗します

致命的: 2 行目のヘッダーのないパッチ フラグメント: ...

.rej問題を修正した後にファイルを再適用する方法はありますか? または、元のパッチを変更して再実行する必要がありますgit applyか?

その場合、元のパッチには数十のファイルのパッチが含まれており、修正されたパッチ ファイル全体git checkoutを再作成するために変更を適用したくないため、これは少し面倒です。git apply

4

3 に答える 3

19

@julian-squires の発言を明確にするために、問題は、ファイルにと.rejの間のいくつかのマイナーなものが欠落していることです。diff a/thefile...@@ -line/columns...

オリジナル.rejファイル

diff a/the/original/file.cs b/the/original/file.cs    (rejected hunks)
@@ -27,9 +27,9 @@ whatever was on that line

行から a/b ファイル名をコピーし、diff以下のような変更インジケーターを追加する必要があります。

更新された.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

その後.rej、通常のパッチのようにファイルを適用できます。

于 2015-02-17T19:03:23.460 に答える
4

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

sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \1\n+++ \2/'

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.

My workflow ended up looking like this:

$ (for i in $(find . -name \*.rej); do
     sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \1\n+++ \2/' -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.

于 2014-11-07T21:18:20.127 に答える