【问题标题】:git bash shell on Windows “Your edited hunk does not apply” (continued)Windows 上的 git bash shell “您编辑的块不适用”(续)
【发布时间】:2017-06-17 18:01:40
【问题描述】:

不久前,我问过this question。我收到了答案,但它并没有解决我遇到的问题,因此建议我创建一个更详细的新问题。

重申一下,当我尝试在 Windows 上使用 git add -p 手动编辑 Git bash shell 中的块时遇到错误(具体来说,我在交互式命令提示时按 e)。这会在 Notepad++(我的默认 .txt 编辑器)中打开一个编辑文件。即使没有对此文件进行任何更改,我也会收到错误消息:

您编辑的大块不适用


作为一个最小的例子,我创建了一个回购,git config core.autocrlf 的值是false(我还尝试了以下值设置为true)。我有一个 .txt 文件 (foobar.txt),我在其中写了 foo,并提交了我的更改。然后我把文件内容改成:

foo 
bar

然后关闭文件。然后我执行git add -p foobar,并收到提示(不知道为什么在这种情况下差异没有完全解决,但它通常对我有用):

diff --git a/foobar b/foobar
index 1910281..a907ec3 100644
--- a/foobar
+++ b/foobar
@@ -1 +1,2 @@
-foo
\ No newline at end of file
+foo
+bar
\ No newline at end of file
Stage this hunk [y,n,q,a,d,/,e,?]?

我回答e。同样,不做任何更改我得到错误:

error: patch failed: foobar:1
error: foobar: patch does not apply
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?

当然,我也尝试过手动修改编辑文件;例如,编辑文件最初看起来像:

# Manual hunk edit mode -- see bottom for a quick guide
@@ -1 +1,2 @@
-foo
\ No newline at end of file
+foo
+bar
\ No newline at end of file
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.

一个示例编辑是:

# Manual hunk edit mode -- see bottom for a quick guide
@@ -1 +1,1 @@
-foo
\ No newline at end of file
+foo
\ No newline at end of file
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.

另一个有趣的地方是我有一个开发者发布的 Windows,它允许我在 Windows 上使用“Bash on Ubuntu”。通过此实用程序使用git add -p,然后尝试手动编辑帅哥,将起作用...所以我的问题是,为什么它不适用于我的 Git bash shell...?

【问题讨论】:

    标签: git shell interactive git-add


    【解决方案1】:

    即使没有对此文件进行任何更改,我也会收到错误:

    Your edited hunk does not apply
    

    在 Git 2.17(2018 年第二季度)中,该错误可能不太常见。
    在此之前,“git add -p”在将结果传递给底层“git apply”之前一直懒于合并拆分补丁,导致出现极端情况错误;准备在大块选择后应用补丁的逻辑。

    请参阅commit 3a8522fcommit b3e0fcfcommit 2b8ea7f(2018 年 3 月 5 日)、commit fecc6f3commit 23fea4ccommit 902f414(2018 年 3 月 1 日)和commit 11489a6commit e4d671c、@9876 (2018 年 2 月 19 日)Phillip Wood (phillipwood)
    (由Junio C Hamano -- gitster --commit 436d18f 中合并,2018 年 3 月 14 日)

    add -p:修复拆分和合并时的计数

    当文件末尾没有新行时,差异记录 在最后一行下方附加“\ No newline at end of file” 文件。
    此行不应计入大块标题。

    修复拆分和合并代码以正确计算没有尾随换行的文件,并将其中一个测试更改为测试拆分没有 尾随换行。


    2020 年第一季度更新:Git 2.25 will rewrite the git-add--interactive.perl script in C。这将改变和修复大块拆分管理。

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题;我将 core.autocrlf 设置为 true,并使用 Notepad++ 作为我的编辑器。

      我已将所有空白设为可见,并注意到在由 Git 添加的块上方和下方的 # cmets 中使用 LF,但块本身使用 CR-LF。所以我应用了Edit->EOL Conversion->Windows Format。然后我可以应用大块,无论是否编辑。

      【讨论】:

        猜你喜欢
        • 2017-06-14
        • 2012-03-19
        • 2016-09-05
        • 2011-03-17
        • 2011-10-16
        • 1970-01-01
        • 2020-07-05
        • 2016-08-13
        • 2021-09-02
        相关资源
        最近更新 更多