git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG] "git stash -p" doesn't work well when splitting nearby changes
@ 2018-01-07 13:45 Kaartic Sivaraam
  0 siblings, 0 replies; only message in thread
From: Kaartic Sivaraam @ 2018-01-07 13:45 UTC (permalink / raw)
  To: Git Mailing list


[-- Attachment #1.1: Type: text/plain, Size: 2672 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 870 bytes --]

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-01-07 13:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-07 13:45 [BUG] "git stash -p" doesn't work well when splitting nearby changes Kaartic Sivaraam

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).