git bash shell on Windows “Your edited hunk does not apply”

六月ゝ 毕业季﹏ 提交于 2019-12-08 04:13:45

问题


I have a very frustrating error when trying to manually edit hunks while using the command:

git add -p

I have already looked through many of the existing questions on this site, including this one, and this one.

I am at the point where I try to manually edit a hunk, make no changes to the file opened by git for manual editing, and still getting the error "Your edited hunk does not apply".

I thought this might have to do with CRLF vs. LF EOL characters. I am editing in Notepad++, and I can see that all of my line endings are CRLF. I naively tried to change all the line endings to LF, but to no avail.

I can also see that all context lines have leading spaces, so that isn't the issue either. Furthermore, I have:

git --global core.autocrlf

set to true.

Any help is greatly appreciated.


Edit: According to VonC's answer, in my specific case I have a permission + content diff. Does this still mean I cannot do:

git add -p

If it were only a permission diff, I understand why this wouldn't be necessary, and the interactive option must be dropped; but in this case, is there a way to still do an interactive add?


回答1:


First, set git --global core.autocrlf to false.
Then clone again your repo, and check the value of core.autocrlf:

cd /path/to/new/clone
git config core.autocrlf

(no --global)

Finally, try again your git add -p (after reporting your modification in your new working tree).

Regarding hunk management, see also "Unexpected result in git-diff".


"Your edited hunk does not apply".

diff --git a/<file-a> b/<file-b> > 
index <short-hash-a>..<short-hash-b> 100644 
--- a/<file-a> 
+++ b/<file-b>
<changes>

If there was no changes (only in permission), adding a "patch" in that case does not make sense: you just git add the file (no -p)

But if there are changes, the question the OP mentioned "git add --interactive “Your edited hunk does not apply”" remains the reference.



来源:https://stackoverflow.com/questions/41917746/git-bash-shell-on-windows-your-edited-hunk-does-not-apply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!