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.
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.
That's the right thing to do.
You can do a git gc
to garbage collect disconnected commits, but it's not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With