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

Re: [BUG] git stash refuses to save after "add -N"

From
Jeff King <peff@peff.net>
Date
Aug 28, 2009, 19:05 UTC
Message-ID
<20090828190531.GB11488@coredump.intra.peff.net>
In-Reply-To
<54e098c45bffbf870bdfcee26b9ddecc.squirrel@intranet.linagora.com>
On Fri, Aug 28, 2009 at 01:02:23PM +0200, Yann Dirson wrote:
Show 10 quoted lines
> $ echo foo > bar
> $ git add -N bar
> $ ./git --exec-path=$PWD stash save
> bar: not added yet
> fatal: git-write-tree: error building trees
> Cannot save the current index state
> 
> Maybe it would require some magic in git-stash to detect/save/restore that
> particular state, or "just" to cause "add -N" to insert an empty file
> instead ?

Yes, there needs to be some magic in git-stash to handle this. There are actually two calls to write-tree: one to save the index and one to save the working tree. I think the working tree one should be OK, because we "git add -u" right beforehand, which means "intent-to-add" files will be saved properly.

For the index case, we unfortunately cannot represent the situation in the index using a tree, which means we cannot have a stash that doesn't lose information. So we have to choose either dropping those index entries, inserting them as blank files, or inserting them with working-tree contents.

When you apply the stash, if they were:
  - dropped, then you may be surprised to find that those files are now
    untracked
  - inserted as working-tree content, then you may not realize that you
    had not _actually_ added that content to the index earlier, and just
    commit it
  - inserted as blank files, then you may be a bit surprised by the fact
    that it looks like you added a blank version, but at least you will
    still see a diff against the working tree file, alerting you to the
    fact that maybe they weren't entirely ready for commit.

So I think of the three, the last one is the least surprising. The other option is to die and force the user to resolve the issue, which is what we do now. It does actually tell you the problem "bar: not added yet", though we could perhaps improve on that message a bit. I think that would require a new 'ls-files' flag to list intent-to-add files.

-Peff
Previous: Yann DirsonNext: Jeff King
Message 2 of 11 in “[BUG] git stash refuses to save after "add -N"”
  1. Yann DirsonAug 28, 2009
  2. Jeff KingAug 28, 2009
  3. Jeff KingAug 28, 2009
  4. Junio C HamanoAug 29, 2009
  5. Jeff KingAug 30, 2009
  6. Junio C HamanoAug 30, 2009
  7. Jeff KingAug 31, 2009
  8. Junio C HamanoAug 31, 2009
  9. Jeff KingAug 31, 2009
  10. Yann DirsonAug 31, 2009
  11. Jeff KingAug 31, 2009

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.