Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git undo last commit

Tags:

git

I merged the wrong way between two branches. I then ran the following:

git reset --hard HEAD^

I am now back at the previous commit (which is where I want to be). Was that the correct thing to do?

The bad commit is still in the repository, is that okay or should I do something else to remove it from the repository?

I have not pushed or committed anything else yet.

like image 828
Justin Avatar asked May 24 '10 14:05

Justin


People also ask

Can I undo last commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


1 Answers

That's the right thing to do.

You can do a git gc to garbage collect disconnected commits, but it's not necessary.

like image 91
James Gregory Avatar answered Sep 18 '22 15:09

James Gregory