Woodchuck
Woodchuck

Reputation: 4444

files not staged after git stash pop

I made some changes to code I'm tracking using git. Those changes were staged (added). Then I stashed them using git stash. Then I unstashed them using git stash pop. At that point the changes were no longer staged. Is this the expected behavior? If so, is it described in git docs?

Upvotes: 3

Views: 526

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45819

You can tell git to try to restore the index state

git stash pop --index

At first glance, it's confusing, and might even seem like a bug, that this isn't the default behavior; especially if you've looked closely enough to know that internally a stash does preserve knowledge of what was staged vs. what was in the working tree when the stash was created. But it is what's documented (see the git stash docs under pop).

The problem, though, is that if there are conflicts when applying the stash, then the index is needed for conflict resolution... so the --index operation then has to fail. So, for better or worse, the default behavior is to do an operation that will more certainly work (even if it has to leave you in a "resolve conflicts" state).

Upvotes: 5

Related Questions