不久前,我问这个问题 https://stackoverflow.com/questions/41917746/git-bash-shell-on-windows-your-edited-hunk-does-not-apply?noredirect=1#comment71040215_41917746。我收到了答案,但它没有解决我遇到的问题,因此建议我创建一个更详细的新问题。
重申一下,当我尝试在 Windows 上的 Git bash shell 中手动编辑一个块时,在使用时遇到错误git add -p
(具体来说,我按e
当交互式命令提示时)。这将在 Notepad++(我的默认 .txt 编辑器)中打开该块的编辑文件。甚至不做任何改变对于此文件,我收到错误:
您编辑的大块不适用
作为一个最小的例子,我创建了一个存储库,其值为git config core.autocrlf
is 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 上不起作用...?