How can I stash my changes and go back to my last check-in in Git?
The story goes like so:
I branched my repo to try and do some changes to the way my wcf stuff works. I checked in my changes to my new branch a day ago when everything was dandy before I started to get a bit weird with wcf. I then started trying out so开发者_运维百科me stuff that hasn't really worked out, though I think i'm on the right track.
Now I don't have time to keep trying this so I'd like to go back to my last checkin but I don't want to lose this stuff forever. Is this possible?
You can stash it (using git stash
) in which case your working directory will be reset to your last checkin (ie. to your HEAD).
Or you can branch your current branch to a new branch, and then commit your changes there. I prefer to use branches to stashes when possible, I see stashes as a much more temporary/transient tool.
I suggest quickly putting your work on another branch:
git stash
git checkout -b new-branch-name
git stash apply
git commit -a -m "commit message here"
git checkout current-branch-name
You could do just the git stash
part, but then your stuff will be in the monolithic stash stack forever. Better to put it somewhere that you can find it again, since you'll need the stash queue for other things later.
精彩评论