Search code examples
gitgit-stash

File state lost after git stash command


echo Hello. > a.txt
git add .
echo Bye. >> a.txt
git status -s
>>> AM

We can see state is AM,
But on doing the following

git stash
git stash pop
git status -s
>>> A

State is A. Why is the M state lost?


Solution

  • It is the expected behavior. To reconstruct it as you expect (save A & M) use

    git stash pop --index
    

    From documentation:

    git-stash(1):
    
    If the --index option is used, then tries to reinstate not only the working
    tree’s hanges, but also the index’s ones. However, this can fail, when you have
    conflicts (which are stored in the index, where you therefore can no longer apply
    the changes as they were originally).