Reputation: 5681
I wanted to check a previous commit.
I am in brach mybranch
where I had a few changes in a file, that's why I did git stash
first.
Then,
git checkout previouscommit
I ran the code, made a few changes that I don't want to save.
Now, how can I go back to mybranch
?
1) I don't want to keep the changes I made in previouscommit
.
2) I want to go back to mybranch
I know I have to do a git stash pop
but I am not sure at what point. Before, or after checking mybranch
? (Also I can't right now because I have done some changes as I said to a file that I don't want to keep and I am not sure how to force to go back to mybranch
.)
Upvotes: 0
Views: 1079
Reputation: 11
I hope this help someone. I used git stash and had a hard time going back to the point where i was before using that command.
1- I used git stash list
it retrieved the last commit code and message before the stash command.
2- I grabbed the retrieved code and used git checkout <commit code>
.
Upvotes: 0
Reputation: 1695
git reset --hard
git checkout mybranch
git stash pop
Upvotes: 0
Reputation: 1602
You can use the following sequence of commands:
git checkout .
git checkout -
git stash pop
The first one throws out the changes you've made on previouscommit
, the second returns you to the previously checked out commit/branch, the last one restores the changes you've stashed.
You can use git checkout mybranch
instead of the second command.
Upvotes: 3