git/list[1] front-page[2] threads[3] people[4] search[5] about
 

stash --patch splitting

From
JMJeffrey Middleton <jefromi@gmail.com>
Date
Feb 19, 2011, 00:49 UTC
Message-ID
<AANLkTimcUi0jKK2AWsw7MHNdHFWbKFSjBixeM0pU74+a@mail.gmail.com>
git stash --patch doesn't appear to play nice with splitting hunks:
	mkdir stash-p &&
	cd stash-p &&
	git init &&
	seq 1 3 > a &&
	git add a &&
	git commit -m "add a" &&
	sed -i 's/[13]/&&/' a &&
	(echo s; echo y; echo n) | git stash -p

That's a file with three lines, a modification to lines 1 and 3, then an attempt to partially stash, splitting and stashing the modification to line 1 but not line 3. It looks like the patch generated to roll back the selected changes is faulty somehow:

	Saved working directory and index state WIP on master: 7cb76e1 add a
	error: patch failed: a:1
	error: a: patch does not apply
	Cannot remove worktree changes
The patch that git-stash attempts to reverse-apply looks sort of reasonable:
	diff --git a/a b/a
	index 01e79c3..88483cf 100644
	--- a/a
	+++ b/a
	@@ -1,3 +1,3 @@
	-1
	+11
	 2
	 3

but it doesn't apply, since the third line is now different in the work tree. The patch I'd really expect to see would have "33" on the third line. I've been staring at all the temporary index files (git-stash.sh:105 and on) and the stash mode in git-add--interactive.perl and trying to figure out where it goes wrong, but I don't think I'm going to get it right now. Maybe one of y'all will immediately see it?

Thanks, Jeffrey

Message 1 of 1 in “stash --patch splitting”
  1. Jeffrey MiddletonFeb 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.