DEV Community

Gaëtan Redin
Gaëtan Redin

Posted on • Originally published at Medium on

How to Undo a GIT Commit

Understand the basics of version control

Hey, I’m sure I’m not in this case. You know you make your git add and then your git commit -m "..." But oh no I forgot a file… Well rather than create a second commit, why not just undo the previous one and recreate it?

Here’s a git alias I use every day:

alias.undo=reset --soft HEAD^
Enter fullscreen mode Exit fullscreen mode

Here’s how to create it:

git config --global alias.undo 'reset --soft HEAD^'
Enter fullscreen mode Exit fullscreen mode

Tips : If you have already pushed your commit into your PR, you will have to use git push -f .

Thanks for reading.

How to undo a commit

Hey, I’m sure I’m not in this case. You know you make your git add and then your git commit -m "..." But oh no I forgot a file… Well rather than create a second commit, why not just undo the previous one and recreate it?

Here’s a git alias I use every day:

alias.undo=reset --soft HEAD^
Enter fullscreen mode Exit fullscreen mode

Here’s how to create it:

git config --global alias.undo 'reset --soft HEAD^'
Enter fullscreen mode Exit fullscreen mode

Tips : If you have already pushed your commit into your PR, you will have to use git push -f .

Thanks for reading.

Learn More

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay