Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert back to specific commit in Git [duplicate]

Tags:

git

git-revert

On my Bitbucket Repo, I see this:

repo

I would like to get back to where I was when I made that commit with an arrow pointing to it.

In my commit where I removed AutoMapper, I removed many files and folders and I know want them all back. I want all to be same as before when I made the 44f31d5 commit.

I thought this would be common, so I tried all sorts from posts I found on SO (you can see my attempt) and this didn't work! I got that last commit by doing

git revert HEAD~1

And committing. I was thinking that would revert my last commit, instead I revert the second (if that makes sense).

like image 660
J86 Avatar asked Jan 02 '17 13:01

J86


People also ask

How do you revert back to a certain commit in git?

Compared to how you revert a Git commit in the command line, reverting a commit takes only 2 clicks with the helpful visual context of GitKraken. To revert a commit with GitKraken, simply right-click on any commit from the central graph and select Revert commit from the context menu.


1 Answers

Here, git revert HEAD~1 will revert to your last commit, while if you want to revert to a specific commit, then use git revert commit_id or in your case you can also use git revert HEAD~2 which will roll you back to previous two commits.

like image 188
Niki Avatar answered Sep 23 '22 11:09

Niki