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

Re: Can't git stash after using git add -N

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 15, 2016, 23:46 UTC
Message-ID
<xmqq8u1j7193.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160315230754.GA12058@cloud>
Josh Triplett <josh@joshtriplett.org> writes:
> After using "git add -N", "git stash" can no longer stash:

I think this is unfortunately one of the fundamental limitations that comes from the way how "stash" is implemented. It uses three tree objects (i.e. HEAD's tree that represents where you started at, the tree that results by writing the index out as a tree, and another tree that would result if you added all the changes you made to the working tree to the index and then writing the resulting index out as a tree), but there are some states in the index that cannot be represented as a tree object. "I know I would eventually want to add this new path, but I cannot decide with what contents just yet" aka "git add -N" is one of them (the other notable state that cannot be represented as a tree object is paths with unresolved conflicts in the index).

"git rm --cached" the path and then running "stash save" would be a workaround, but then you'd probably need to use "--untracked" hack when you run "stash save" if you are stashing because you are going to do something to the same path in the cleaned-up working tree.

Previous: Josh TriplettNext: Josh Triplett
Message 2 of 9 in “Can't git stash after using git add -N”
  1. Josh TriplettMar 15, 2016
  2. Junio C HamanoMar 15, 2016
  3. Josh TriplettMar 16, 2016
  4. Junio C HamanoMar 16, 2016
  5. Duy NguyenMar 16, 2016
  6. Josh TriplettMar 16, 2016
  7. Jeff KingMar 16, 2016
  8. Junio C HamanoMar 16, 2016
  9. Jeff KingMar 16, 2016

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.