【问题标题】:trailing whitespace. patch does not apply尾随空格。补丁不适用
【发布时间】:2022-01-13 15:20:06
【问题描述】:

我有 3 个文件 a\test.txt、b\test.txt 和 c\test.txt:

a\test.txt:

x
y
z

b\test.txt:

x
z
p
q

c\test.txt:

x
y

现在我在 a 和 b 之间创建了一个补丁:

git diff --no-prefix --binary a b > mypatch.patch

导致这个补丁:

diff --git a/test.txt b/test.txt
index 1b2c8f8..e0b3aec 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
 x
-y
-z
\ No newline at end of file
+z
+p
+q
\ No newline at end of file

接下来我想在c\test.txt上应用mypatch.patch:

cd c:\
git apply --ignore-space-change --ignore-whitespace ../mypatch.patch

我得到错误:

../mypatch.patch:10: trailing whitespace.
z
../mypatch.patch:11: trailing whitespace.
p
error: patch failed: test.txt:1
error: test.txt: patch does not apply

我在这里阅读了很多关于 SO 的帖子,但仍然没有设法将其应用到任何想法?

我在 mypatch.patch 中没有看到任何尾随空格

【问题讨论】:

    标签: git


    【解决方案1】:

    补丁不适用的事实与尾随空格无关。

    补丁尝试删除y 和z 行,但z 在您尝试应用它的文件中不存在 (c/text.txt)。

    以下内容将适用:

    diff --git a/test.txt b/test.txt
    index 66455a1..1a0d96d 100644
    --- a/test.txt
    +++ b/test.txt
    @@ -1,2 +1,4 @@
     x
    -y
    \ No newline at end of file
    +z
    +p
    +q
    \ No newline at end of file
    

    【讨论】:

      【解决方案2】:

      请尝试patch -p1 < filename.patch。

      顺便说一句,这里有一个类似的问题:My diff contains trailing whitespace - how to get rid of it?

      【讨论】:

        猜你喜欢
        • 2015-05-21
        • 2011-06-13
        • 2014-04-25
        • 2014-11-08
        • 1970-01-01
        • 2015-07-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多