I recently made two changes to nearby lines (approx. 3 lines b/w them) in a file and wanted to stash one part of it and not the other. I tried to use "git stash -p" for this. I split the hunk of concern (of course, they came out as a single hunk) and gave 'y' for one and 'n' for the other. The stash was created successfully but the discarding that change from the work tree failed with the following error, error: patch failed: Documentation/gitsubmodules.txt:57 error: Documentation/gitsubmodules.txt: patch does not apply Cannot remove worktree changes I guess this a bug that has been for a very long time now (I generally use the one built from 'next' but this error occurs even if I use 2.11)? Or is this intentional? I couldn't glean any reason for that, though. In case you need a reproduction recipe, git init stash-patch-test && cd stash-patch-test && echo 'Let us put some lines to ensure Git would allow us to split a change we make to this text. It should be a little longer, I guess. A little more. Almost there. And DONE.' >test-files && git add . && git commit -m "Initial commit" Apply this patch or do something similar to what it does, diff --git a/test-files b/test-files index daa67cf..d3142e7 100644 --- a/test-files +++ b/test-files @@ -1,7 +1,7 @@ -Let us put some lines to ensure +Let's put some lines to ensure Git would allow us to split a change we make -to this text. +to this text It should be a little longer, I guess. A little more. Almost there. Then, $ git stash -p diff --git a/test-files b/test-files index daa67cf..d3142e7 100644 --- a/test-files +++ b/test-files @@ -1,7 +1,7 @@ -Let us put some lines to ensure +Let's put some lines to ensure Git would allow us to split a change we make -to this text. +to this text It should be a little longer, I guess. A little more. Almost there. Stash this hunk [y,n,q,a,d,/,s,e,?]? s Split into 2 hunks. @@ -1,3 +1,3 @@ -Let us put some lines to ensure +Let's put some lines to ensure Git would allow us to split a change we make Stash this hunk [y,n,q,a,d,/,j,J,g,e,?]? n @@ -2,6 +2,6 @@ Git would allow us to split a change we make -to this text. +to this text It should be a little longer, I guess. A little more. Almost there. Stash this hunk [y,n,q,a,d,/,K,g,e,?]? y Saved working directory and index state WIP on master: f0dff20 Initial commit error: patch failed: test-files:1 error: test-files: patch does not apply Cannot remove worktree changes -- Kaartic Quote: "Be creative. Be adventurous. Be original. And above all else, be young." - Wonder Woman
Attachment:
signature.asc
Description: OpenPGP digital signature