Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stashing a file added with --intent-to-add

Tags:

git

git-stash

I am using the --intent-to-add option with git add to easily add files using git commit -a. However, it seems like this confuses git stash. For example:

git init
touch a
git add a
git commit -m 1
touch b
git add --intent-to-add b
git stash --include-untracked

gives output from git stash :

error: Entry 'b' not uptodate. Cannot merge.
Cannot save the current worktree state

Why does this happen? Can it be fixed?

like image 420
Håkon Hægland Avatar asked Jan 13 '16 10:01

Håkon Hægland


1 Answers

Given a git stash followed by git stash pop will clear the index anyway, I would start with git reset --keep to clear the index. (With --keep, this won't change your local files or your commits, it only clears the index.)

git reset --keep
git stash --include-untracked

Once you've done the stuff you needed the stash for, you have to redo git add --intent-to-add b since you undid it with the reset:

git stash pop
git add --intent-to-add b

As for why this happens in the first place, I don't know. Seems like a bug to me... You can stash a regular git add, afterall.

like image 129
joanis Avatar answered Oct 17 '22 20:10

joanis