git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Git Mailing list <git@vger.kernel.org>
Subject: [BUG] "git stash -p" doesn't work well when splitting nearby changes
Date: Sun, 7 Jan 2018 19:15:40 +0530	[thread overview]
Message-ID: <aa43f1ff-9095-fb4d-43bc-bf8283b7dabb@gmail.com> (raw)


[-- 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 --]

                 reply	other threads:[~2018-01-07 13:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa43f1ff-9095-fb4d-43bc-bf8283b7dabb@gmail.com \
    --to=kaartic.sivaraam@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).