Reputation: 29885
In Git, I can use the revert command to revert back to a previous commit. But this assumes that I have already made a commit to the current code that I want to undo. But suppose I do an initial commit and then want to make changes to try something out. After trying things out, I decide that I want to undo the changes I just made and go back to the state of my last commit. The only way I see that I can do this is to first commit the changes I just made (even though I really don't need them) and then revert back to the previous commit. Is there a way to just go back to the previous commit without committing the current changes? I also know that there is a stash but the documentation seems to imply that you use this when you want to switch to a different branch. But I really don't want to switch to a different branch. Maybe the solution is just to create a new branch to test out my modified code? And if I don't like it, just switch back to the previous branch?
Upvotes: 0
Views: 89
Reputation: 3512
Go to last commit state by git checkout .
This will discard your local change. Depends on your intention, this may or may not be what you indended
Upvotes: 1