Ok, so i have run into this a few times and it's really annoying. Scenario:
modify a file say a.txt (add say two lines)
stash it
stash apply
git reset
remove the two lines added to a.txt because you want to commit and push these partial changes
git add a.txt
git commit the above, and push the changes (push irrelevant for this discussion)
git reset --hard
now do git stash apply
Now, a.txt is the same version as was committed, it should be the version that i stashed. Thus i have now lost my changes to a.txt. If i go back one commit, ie. git co head~1 and apply my stash it still doesn't work.
A fix would be much appreciated.
Thanks.
Okay, so i tried extensively with a script to reproduce this, trying many variations of merge commits etc and could not get reproduce it. Unfortunately it's very difficult in a script for me to reproduce the complexity of the source tree i was working on when this happened. The one other caviat i'm thinking of now is that i had multiple stashes based on different versions of the same branch, with some files pushed, some files committed locally that were in those stashes. My commands only ever applied the last stash as described earlier, but during this whole process, i lost 2 stashes, they just disappeared when executing git stash list. So i maybe this somehow also affects the outcome. If anybody runs into anything similar please update this thread. If anybody is interested in taking my testing further, i can post my script (completely self contained, creates the repository and everything). In the mean time i will continue using git and the next time it happens maybe i get a better idea of what happened.
Also this happened at work, hence why i can't supply original code, but i will take a look at the gitk results again and post my findings as that might help.
Thanks for all the help!
Ok, so looking at gitk shows that my stash is based on an index (which i think is normal), then that index is based off of a commit, that seems to only exist in the stash (this does not make sense. Ie. the save has the commit message i gave it when i committed it to my private branch, but somehow, my private branch does not have that commit as part of the gitk path.