Reputation: 21
I am mid-branch work but I am thinking to temporarily save my changes I can use git stash save --keep-index. This will stash the changes and leave my local copy unchanged, so just incase something happens to my local copy I can git stash pop and restore the changes to any branch.
I am asking because I didn't want to experiment with actual work.
Thanks, Tom
Upvotes: 2
Views: 2111
Reputation: 118292
git stash pop
does not just reset your working tree to the stashed index.
It reapplies the stashed changes to your working tree. So, before popping the stash, you have to do a hard reset to the commit that the stashed changes were based on.
This is, of course, possible. But there's no reason for this to be so complicated. Just commit the changes to date, and continue working. If you want to back out, resetting to the commit is easy.
Commits are cheap. Commits are flexible. You can always rebase and squash everything, once you finish working, into a single commit.
And if the changes are substantive, a new branch, in addition to just a commit, can always be started, which gives additional flexibility for managing the ongoing work.
Upvotes: 1