Home > OS >  git stash seems not to work when new files have been added?
git stash seems not to work when new files have been added?

Time:07-11

I don't have the exact setup on me right now, but I remember adding a couple of new files to my tree and then wanting to stash them. Instead of stashing correctly, git stash returned an error:

error: Entry 'x' not uptodate. Cannot merge.

It seems weird, since the error message has to do with merging, but that's what I got back from git stash.

Does anyone know why and in what circumstances git stash returns an error such as this?

CodePudding user response:

This is because the new files you have are not added to the index (they are new files) and are not being tracked and you are attempting to stash the changes. You can do this:

git add <file1> <file2> ...

and the git stash should work.

If it doesn't, you can force the index to refresh and try again:

git update-index --really-refresh

Followed by git stash.

CodePudding user response:

error: Entry 'x' not uptodate. Cannot merge.

This error is ... not a good message, but it means you're in the middle of a conflicted merge. Presumably you recently ran git merge or git rebase or some other command that started a merge. This command, whatever it was, was unable to finish the merge.

Running git status now will tell you which files are unmerged. You must finish merging them before you can move forward. Alternatively, you can use git reset or another equivalent command to "move backwards" as it were, but you'll lose uncommitted work you have done since the failed merge failed.

If the command that was unable to finish was git merge, you can use git merge --abort, which is more or less equivalent to git reset --hard. If the command that was unable to finish was git rebase, you can use git rebase --abort, which is more or less equivalent to git reset --hard ORIG_HEAD. If the command that was unable to finish was git stash apply (perhaps invoked via git stash pop), there is no git stash command that will clean up, and you may be in fairly deep trouble here. This is one of several reasons that I suggest Git users (regardless of how beginner or advanced they are) try to avoid using git stash: its corner cases can be really miserable. (Once you're an advanced Git user, you'll know what to do for the most-miserable cases, but that won't make you any happier.

  • Related