Undoing a Commit

Chindalath Traymany
1 min readApr 14, 2021

--

Photo by Nathan Dumlao on Unsplash

It was just a regular day on my code editor when I made a blunder. I had accidentally staged all the files in my directory using git add .! It wasn’t until I had already committed lines and lines of code that I had realized my mistake — whoops!

But it wasn’t all bad — I had not yet pushed any of the changes to a remote repository. This meant less work to fix!

Luckily for me, the fix for this is simple. All I had to do was run git reset HEAD~ in my terminal.

So what exactly does this command do? Well, according to Stack Overflow:

This command is responsible for the undo. It will undo your last commit while leaving your working tree (the state of your files on disk) untouched. You’ll need to add them again before you can commit them again.

So if you’ve made the same mistake as me — simply run git reset HEAD~, make sure all your changes are correct, and stage and commit your file(s) as normal.

Et voila! Happy coding!

--

--

Chindalath Traymany
Chindalath Traymany

Written by Chindalath Traymany

Laotian-American woman pursuing my passion for mentally stimulating and complex problem-solving through programming.

No responses yet