Windows上的git bash shell“您编辑的大块不适用”(续) [英] git bash shell on Windows “Your edited hunk does not apply” (continued)
问题描述
不久前,我问过这个问题。我收到了一个答案,但它并没有解决我遇到的问题,所以我被建议创建一个更详细的新问题。
Not too long ago, I asked this question. I received an answer, but it did not solve the issue I was having, so I was advised to create a new question with more detail.
只是要重申,我是在使用 git add -p
时(尤其是我按 e
当交互式命令提示时)。这将在Notepad ++(我的默认.txt编辑器)中打开一个编辑文件。即使未对此文件进行任何更改,我也会收到错误信息:
Just to reiterate, I am getting an error when trying to manually edit a hunk in the Git bash shell on Windows, when using git add -p
(specifically, I press e
when prompted by the interactive command). This opens an edit file for the hunk in Notepad++ (my default .txt editor). Even without making any changes to this file, I am given the error:
编辑后的大块不适用
作为一个最简单的例子,我创建了一个repo,值为 git config core.autocrlf
是 false
(我也尝试了下面的值设置为 true
)。我有一个.txt文件( foobar.txt
),我写了 foo
并提交我的更改。然后我将文件的内容更改为:
As a minimal example, I have created a repo, value of git config core.autocrlf
is false
(I've also tried the following with value set to true
). I have a .txt file (foobar.txt
), I write foo
in it, and commit my changes. Then I change the contents of the file to:
foo
bar
然后关闭文件。然后我做了 git add -p foobar
,然后提示(不确定为什么diff在这种情况下没有干净地工作,但它通常对我有效):
and then close the file. I then do git add -p foobar
, and am prompted (not sure why the diff didn't work out cleanly in this case, but it generally does work for me):
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
。再次,没有做任何改变,我得到的错误:
to which I answer e
. Again, without making any changes I get the error:
error: patch failed: foobar:1
error: foobar: patch does not apply
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?
当然,我也尝试对手动编辑文件;例如,编辑文件最初看起来像:
Of course, I have also tried making changes to the manual hunk edit file; for example, the edit file will initially look like:
# 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.
一个示例编辑是:
A sample edit would be:
# 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上的Ubuntu的Bash。通过此实用程序使用 git add -p
,然后尝试手动编辑hunks,将会工作...所以我的问题是,为什么它不适用于Git bash shell for我...?
Another interesting point is that I have a developer's release of Windows, which allows me to use "Bash on Ubuntu on Windows". Using git add -p
through this utility, and then trying to manually edit hunks, will work... so my question is, why does it not work on Git bash shell for me...?
推荐答案
我刚刚有同样的问题;我将core.autocrlf设置为true,并且使用Notepad ++作为我的编辑器。
I've just had the same problem; I have core.autocrlf set to true, and am using Notepad++ as my editor.
我将所有空格都设置为可见,并且注意到在上面和下面的#大块,由Git添加,使用LF,但大块本身使用CR-LF。所以我应用了Edit-> EOL Conversion-> Windows Format。然后,我可以应用这个庞然大物,无论是否进行编辑。
I have all whitespace made visible, and noticed that in the # comments above and below the hunk, added by Git, use LF, but the hunk itself uses CR-LF. So I applied Edit->EOL Conversion->Windows Format. I could then apply the hunk, with or without edits.
这篇关于Windows上的git bash shell“您编辑的大块不适用”(续)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!