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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

👋 Kindness is contagious

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

Okay