15

リポジトリにいくつかのパッチを適用しようとしていますが、patch does not applyparams を指定しない限りメッセージが表示されます--ignore-space-change --ignore-whitespace。これらのキーを使用しても一部のパッチは適用できません。手動で解決する必要がある競合があると表示されます。(しかし、実際には競合はありません。自動マージでこれが解決されたに違いありません)

実験を行いました。レポのコミットからパッチを作成し、マスターを以前のコミットにリセットし、ファイルからパッチを適用しようとしました。同じエラーメッセージ。

なぜこれが起こるのでしょうか?

UPDコマンドは非常に簡単です:

git format-patch -o ../_patches 0f3bf7874c32b22256ae2d9dc00b1afd6464e43c
git reset --hard 0f3bf7874c32b22256ae2d9dc00b1afd6464e43c
git am ../_patches/0001-test2.patch

(この ID は、最後の前の最初のコミットを参照します)

4

2 に答える 2

16

--keep-crにフラグを渡す必要がありますgit am。残念ながら、標準が競合しているため (電子メール ワークフローとローカル)、選択肢はあまりありません。

.gitattributesファイルの設定も試してみてください。問題を再現しようとして、ファイルを CRLF が必要であると指定したときに、問題を解決することができました。最初にファイルを正規化せずに、ファイル全体が変更されたものとして表示されたことに注意してください。私は一般的にこれで a を使用.gitattributesします:

.gitattributes  export-ignore
.gitignore      export-ignore

*.txt           text
*.C             text trailing-space space-before-tab -indent-with-non-tab
*.rst           text trailing-space space-before-tab -indent-with-non-tab
*.clj           text trailing-space space-before-tab -indent-with-non-tab

*.c             text diff=cpp trailing-space space-before-tab -indent-with-non-tab
*.cpp           text diff=cpp trailing-space space-before-tab -indent-with-non-tab
*.h             text diff=cpp trailing-space space-before-tab -indent-with-non-tab
*.hpp           text diff=cpp trailing-space space-before-tab -indent-with-non-tab
*.py            text diff=python trailing-space space-before-tab -indent-with-non-tab
*.tex           text diff=tex
*.java          text diff=java trailing-space space-before-tab -indent-with-non-tab
*.pl            text diff=perl trailing-space space-before-tab -indent-with-non-tab
*.php           text diff=php
*.rb            text diff=ruby trailing-space space-before-tab -indent-with-non-tab

*.vcproj        eol=crlf
*.dsp           eol=crlf
*.dsw           eol=crlf

*.sh            eol=lf

*.jpg           binary
*.png           binary
*.gif           binary
*.tiff          binary

gitattributes man pageに従って、行末を正規化する必要があります。core.autocrlf別の SO ユーザーも、クリーンなコミットとパッチを取得するためにオフにしました。

バグを再現しようとしています

$ git init repo
Initialized empty Git repository in c:/tmp/git-eol/repo/.git/
$ cd repo
$ git config --local core.autocrlf false
$ vim foo.txt
$ git add foo.txt
$ git commit -m "Add foo."
[master (root-commit) 3903abd] Add foo.
 1 file changed, 3 insertions(+)
 create mode 100644 foo.txt
$ vim foo.txt
$ git st
## master
 M foo.txt
$ git commit -m "Add more foo." -a
[master 03e991a] Add more foo.
 1 file changed, 2 insertions(+)
$ git format-patch HEAD~1
0001-Add-more-foo.patch
$ vim 0001-Add-more-foo.patch

作成されたパッチ ファイルを見ると、次のように表示されます。

ご覧のとおり、キャリッジ リターン ( ^Ms) はパッチに保持されています。とありcore.autocrlf=falseます。続けて、私は見る:

$ git reset --hard HEAD~1
HEAD is now at 3903abd Add foo.
$ git am 0001-Add-more-foo.patch
Applying: Add more foo.
error: patch failed: foo.txt:1
error: foo.txt: patch does not apply
Patch failed at 0001 Add more foo.
The copy of the patch that failed is found in:
   c:/tmp/git-eol/repo/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
$ git am --abort

そのため、パッチはそのままでは適切に適用されません。ただし、使用--keep-crは予想どおりでした:

$ git am --keep-cr 0001-Add-more-foo.patch
Applying: Add more foo.
$

わかった。core.autocrlf=trueそれでは、 (別のリポジトリで)これを試してみましょう:

# Removed the initial commands...
$ git format-patch HEAD~1
0001-Add-more-foo.patch
$ git reset --hard HEAD~1
HEAD is now at 525b5aa Initial commit.
$ git am 0001-Add-more-foo.patch
Applying: Add more foo.
$ git config --get core.autocrlf
true

この場合のパッチには、いたるところに LF エンディングがありました。

于 2013-04-22T10:13:12.760 に答える