Oh no I made a mistake! Revert! Reset! Re-something!

TLDR: git reset --hard is the key.

This often happens to me when I’m in the midst of fixing a merge conflict. Something goes wrong and I’m not sure what I did. Sadly whatever I’ve done is beyond the magic of control z.

In those instances, I just want to go back in time. Thanks to the fact I am ultra risk adverse and mighty trigger happy on pushing minute commits to my repo, there’s not much work to lose. Particularly for merge conflicts.

This article by Git demonstrates the different ways to go back in time and the implications of each. However I encounter the same problem with this article as with others. On one hand, it’s really detailed. Too detailed for me, as I’m after a “quick” answer. Great for learning, but also there’s a lot to take in and remember. On the other hand, it’s not detailed enough. After reading the detail I used git reset, but it didn’t produce the outcome I expected.

Here’s the trick. You need to type in git reset --hard. That deletes everything in your working directory and resets it to the previous commit.

If you type in git reset, it’s a bit awkward. It unstages everything from your working directory. Also the merge conflicts are mysteriously gone. So whilst git reset is probably a safer bet for someone that knows that they are doing, it’s not great for me!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.