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 16, 2016, 04:51 UTC
Message-ID
<xmqqvb4n58ko.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160316020000.GB12130@cloud>
Josh Triplett <josh@joshtriplett.org> writes:
> As far as I can tell, if I run "git add -N" on a file, and then commit
> without adding the file contents, it gets committed as an empty file.

Is that true? Git once worked like that in earlier days, but I think write-tree (hence commit) would simply ignore intent-to-add entries from its resulting tree.

> Could stash save it exactly as if I'd done "git add" of an empty file at
> that path and then filled in the contents without adding them?

As I said, there is no space for a tree object to say "this one records an empty blob but it actually was an intent-to-add entry" and "this other one records an empty blob and it indeed is an empty blob". So "stash pop" (or "stash apply") would fundamentally be unable to resurrect the exact state after "add -N".

Show 6 quoted lines
>> "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.
>
> Right; I do specifically want to save the working-tree files.

Then "git add" that path before "stash save" would probably be a better workaround.

Previous: Josh TriplettNext: Duy Nguyen
Message 4 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.