The last commit I made to the master branch is where I want to get everything back to. I made a branch and commit and even merge it to the master branch. However everything goes wrong after I merge that branch.
I would like to delete that branch entirely and restore everything back to the last master commit. How do I do that?
PS: I did try git branch -D [branch-name] (which works well if i don’t merge to master branch) , but the wrong files and dirs still in master branch
Checkout the master branch (
git checkout master). Then view the log (git log) and copy the SHA of the commit that you would like to go back to.Then reset back to that commit with:
An example of a SHA is f75b7ca5beb502e7f99434ea47e631bdd18fef13. You can also use the –soft switch if you would like to keep the changes you have made as staged changes and the –mixed switch to keep them as unstaged changes.
And then you can delete your branch if you still want to.
P.S. the git reset command is very useful, I’ve written a blog post about it here or checkout any of the famous git websites for more tips on how to use it.