Håkon Hægland
Håkon Hægland

Reputation: 40758

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

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?

Upvotes: 13

Views: 527

Answers (1)

joanis
joanis

Reputation: 12229

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.

Upvotes: 5

Related Questions