Reputation: 29178
I don't really understand git stash
. According to the documentation, I may use stash
to save my current repository state in the same say as if I backup/restore my repository somewhere.
Apparently what I did was something else...
I first wanted to completely save my work, even though the untracked files. So I did:
git stash -u
Then I did some not very important work. At the end I wanted to come back to my original work so I used this command:
git stash pop
The weird thing is that I got this message:
Auto-merging foo.c
CONFLICT (content): Merge conflict in foo.c
And inside my file I got this
++<<<<<<< Updated upstream
++=======
+ // something
+
++>>>>>>> Stashed changes
Actually, instead of using stash I could have used:
cp -R myproject myproject_backup
And later restore my work:
rm myproject && mv myproject_backup myproject
What did I misunderstand?
Upvotes: 1
Views: 878
Reputation: 9886
It appears that the work you did after pushing a stash affected the files you had in the stash (only you know what happened but I suspect some interaction with a remote repo), so it was unable to re-apply the change when you popped it out of the stash.
On the same page you linked it also says:
The working directory must match the index. Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards.
There's a lot more information on a few other SO questions, e.g. this one, about getting back to a clean state with the stash removed and your changes just in your working tree.
Yes you could have copied the directory away and restored it, but you'd have lost the 'work' you did in between.
Upvotes: 1
Reputation: 72215
Stash works by taking the difference between the checked-out revision and your current working directory, and storing this diff as a temporary commit in a separate location.
This allows you to stash your work, switch to a different branch, do something, switch back, and pop your stash.
However, if you try to pop your stash onto a different revision than the one you pushed it from, for example because you pulled the origin in-between, it can well happen that some of the changes in the temporary commit conflict with other commits that were added. In this case you have to merge.
Upvotes: 1