threads / bug / 23522

[QUESTION] or [BUG] Could not stash new bin files

Subject: [QUESTION] or [BUG] Could not stash new bin files

## tl;dr

3 messages between Apr 19, 2010 and Apr 19, 2010.

replies: 2people: 3as markdown or json

Arnauld Van Muysewinkel· Apr 19, 2010, 08:19 UTC · lore

I'm quite new to Git (using it since a few weeks only) and really like this tool. This is a great improvement over Svn that I was using until now. (Still using it for the company master repository though.)

I have the following problem:

I want to stash new files. I tried the combination "git add" / "git stash" but it does not work. Did I do something wrong, is it a special case, or some kind of bug? Does anybody have a clue?

Here are the details:
    $ git add -N XXX/src/jrxml/*.xls
    $ git stash save --keep-index "Improving performance of views"
    XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-new.xls: not added yet
    XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-old.xls: not added yet
    fatal: git-write-tree: error building trees
    Cannot save the current index state
    $ git status
    # On branch MS9
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   XXX/.settings/org.eclipse.wst.common.component
    #       new file:   XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-new.xls
    #       new file:   XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-old.xls
    #
    # Changed but not updated:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working
directory)
    #
    #       modified:   XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-new.xls
    #       modified:   XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-old.xls
    #
    $ git version
    git version 1.7.0.2.msysgit.0
Specificities:
* I have a file in the index that I do not want to stash
* The two new files are binary files
* I'm running this on windows (msysgit)
Please tell me, should you need any extra information.
-- 
Arnauld Van Muysewinkel
Jonathan Nieder· Apr 19, 2010, 09:35 UTC · re: Arnauld Van Muysewinkel · lore

Re: [QUESTION] or [BUG] Could not stash new bin files

Hi Arnauld,
Arnauld Van Muysewinkel wrote:
Show 5 quoted lines
>     $ git add -N XXX/src/jrxml/*.xls
>     $ git stash save --keep-index "Improving performance of views"
>     XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-new.xls: not added yet
>     XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-old.xls: not added yet
>     fatal: git-write-tree: error building trees
Yes, this is a known problem [1].

To explain this requires a bit of a digression into how ‘git stash’ works. It is a neat script (in commit f2c66ed1, when it was added, it was only 160 lines or so), especially because it uses ordinary git commits and reflogs to maintain its data. You have probably seen what it looks like in gitk. A particular stashed version looks like this:

                        index
                       /     \
  history ... --- HEAD ------- work tree
and these are all ordinary commits.

An unsolved problem with this data structure is that it does not store information that can be stored in the index but not a commit. This is the case for the CE_INTENT_TO_ADD bit [2], and that it cannot be used in commits is very deliberate: trying to commit immediately after an add -N is almost certainly a sign of a mistake. See 331fcb598 (git add --intent-to-add: do not let an empty blob be committed by accident, 2008-11-28) and the preceding commits for more on this.

One workaround is to make sure the intent-to-add bit is not set when stashing from such a state. For example, you can ‘git add’ the file, or ‘git rm --cached’ it [3].

I suspect the correct fix would be to use the commit message for the index commit to record the intent to add.

[...]
> Specificities:
> 
> * I have a file in the index that I do not want to stash

Could you explain this further? The stash currently saves everything about the current state (except files not in the index nor HEAD).

> * The two new files are binary files

Hope that helps, Jonathan

[1] See, for example, this discussion: http://thread.gmane.org/gmane.comp.version-control.git/127290

[2] CE_VALID and CE_SKIP_WORKTREE also, but I suspect no one is worried about making stash track them.

[3] If you use git rm and then stash, watch out for the following bug. http://thread.gmane.org/gmane.comp.version-control.git/145228

Jeff King· Apr 19, 2010, 12:41 UTC · re: Jonathan Nieder · lore

Re: [QUESTION] or [BUG] Could not stash new bin files

On Mon, Apr 19, 2010 at 04:35:23AM -0500, Jonathan Nieder wrote:
Show 7 quoted lines
> >     $ git add -N XXX/src/jrxml/*.xls
> >     $ git stash save --keep-index "Improving performance of views"
> >     XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-new.xls: not added yet
> >     XXX/src/jrxml/SubCellMatrixCompared-EXPLAIN-old.xls: not added yet
> >     fatal: git-write-tree: error building trees
> 
> Yes, this is a known problem [1].
Thanks for the pointer.

Re-reading that thread, and considering the fact that this comes up so rarely, I think leaving it as an error is fine. We could possibly give a bit more advice on how to proceed, though.

Show 6 quoted lines
> > Specificities:
> > 
> > * I have a file in the index that I do not want to stash
> 
> Could you explain this further?  The stash currently saves everything
> about the current state (except files not in the index nor HEAD).

Yeah, I'm not really sure why intent-to-add is being used here at all, instead of regular "git add".

But if the real problem is wanting to stash part of your changes, then the best thing is probably to use the interactive "git stash -p".

> > * The two new files are binary files

I don't think that is relevant here. The intent-to-add bit is the problem.

-Peff

← back to recent threads