【发布时间】: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