{"thread":{"id":"47558","subject":"[BUG] \"git stash -p\" doesn't work well when splitting nearby changes","startedAt":"2018-01-07T13:45:57Z","lastAt":"2018-01-07T13:45:57Z","messageCount":1,"participants":["Kaartic Sivaraam"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"336083","messageId":"aa43f1ff-9095-fb4d-43bc-bf8283b7dabb@gmail.com","threadId":"47558","inReplyTo":null,"subject":"[BUG] \"git stash -p\" doesn't work well when splitting nearby changes","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-01-07T13:45:40Z","receivedAt":"2018-01-07T13:45:57Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"I recently made two changes to nearby lines (approx. 3 lines b/w them)\nin a file and wanted to stash one part of it and not the other. I tried\nto use \"git stash -p\" for this. I split the hunk of concern (of course,\nthey came out as a single hunk) and gave 'y' for one and 'n' for the\nother. The stash was created successfully but the discarding that change\nfrom the work tree failed with the following error,\n\nerror: patch failed: Documentation/gitsubmodules.txt:57\nerror: Documentation/gitsubmodules.txt: patch does not apply\nCannot remove worktree changes\n\nI guess this a bug that has been for a very long time now (I generally\nuse the one built from 'next' but this error occurs even if I use 2.11)?\nOr is this intentional? I couldn't glean any reason for that, though.\n\nIn case you need a reproduction recipe,\n\ngit init stash-patch-test &&\ncd stash-patch-test &&\necho 'Let us put some lines to ensure\nGit would allow us to split\na change we make\nto this text.\nIt should be a little longer, I guess.\nA little more.\nAlmost there.\nAnd DONE.' >test-files &&\ngit add . &&\ngit commit -m \"Initial commit\"\n\n\nApply this patch or do something similar to what it does,\n\ndiff --git a/test-files b/test-files\nindex daa67cf..d3142e7 100644\n--- a/test-files\n+++ b/test-files\n@@ -1,7 +1,7 @@\n-Let us put some lines to ensure\n+Let's put some lines to ensure\n Git would allow us to split\n a change we make\n-to this text.\n+to this text\n It should be a little longer, I guess.\n A little more.\n Almost there.\n\nThen,\n\n$ git stash -p\ndiff --git a/test-files b/test-files\nindex daa67cf..d3142e7 100644\n--- a/test-files\n+++ b/test-files\n@@ -1,7 +1,7 @@\n-Let us put some lines to ensure\n+Let's put some lines to ensure\n Git would allow us to split\n a change we make\n-to this text.\n+to this text\n It should be a little longer, I guess.\n A little more.\n Almost there.\nStash this hunk [y,n,q,a,d,/,s,e,?]? s\nSplit into 2 hunks.\n@@ -1,3 +1,3 @@\n-Let us put some lines to ensure\n+Let's put some lines to ensure\n Git would allow us to split\n a change we make\nStash this hunk [y,n,q,a,d,/,j,J,g,e,?]? n\n@@ -2,6 +2,6 @@\n Git would allow us to split\n a change we make\n-to this text.\n+to this text\n It should be a little longer, I guess.\n A little more.\n Almost there.\nStash this hunk [y,n,q,a,d,/,K,g,e,?]? y\n\nSaved working directory and index state WIP on master: f0dff20 Initial\ncommit\nerror: patch failed: test-files:1\nerror: test-files: patch does not apply\nCannot remove worktree changes\n\n\n\n-- \nKaartic\n\nQuote: \"Be creative. Be adventurous. Be original. And above all else, be\nyoung.\" - Wonder Woman\n\n"}]}