tags:

views:

1207

answers:

2

Hi,

I make a change and then I 'git stash' and then I 'git stash apply'

My question is 1. why after I 'git stash apply', my change becomes 'staged'? i.e. I won't see anything if I do 'git diff', I only see my difference if I do 'git diff --cached'?

  1. Is there anyway to 'unstage' my changes staged by 'git stash apply' command?

  2. Is there any git command basically let me to 'make a backup of my change, reset it to the HEAD and the copy my backup back'? I thought 'git stash' and then 'git stash apply' is that command, but some how it 'staged' all my changes? Is there any equivalent which let me 'git stash apply without the staged my changes part?

Thank you.

+4  A: 

If you find that your changes are unexpectedly staged, do:

git reset HEAD

I usually only see this if there is a conflict when applying the stashed changes. You will want to check to see whether this is the case before doing the git reset.

The git stash command is the most appropriate command for your use case. I use it all the time for exactly this purpose.

Greg Hewgill
+2  A: 

I think that something may be wrong in your configuration as while git stash records the state of the index and the working tree before resetting to the latest commit, git stash apply should only attempt to restore the state of the index if you use the --index option.

One possible point of confusion is that if you have conflict (i.e. there are merge conflicts introduced because the stash is being applied to a different commit where the files affected by the stash have been changed since the commit at which the stash was made), then if you use mergetool to resolve the conflicts, mergetool will automatically stage changes to the files on a successful resolution.

As Greg Hewgill states a simple reset will unstage all staged changes.

git reset
Charles Bailey
I have the exact same problem as the OP.when git stash apply gives a conflict, changes are staged.I do not use any tool for conflict resolution, only my code editor.Any other suggestion about who is staging the stashed changes?Note: msysgit on windows!
Gauthier
Me, too. Using git 1.6.0.6 under Debian Lenny. Really strange...
Boldewyn
The only config that comes remotely close to a culprit would be core.logallrefupdates = true, but I doubt, it has to do something with it.
Boldewyn