DEV Community

Cover image for How to undo the most recent local commits in Git?
Ankur Singh
Ankur Singh

Posted on

1 1

How to undo the most recent local commits in Git?

Step 1:

git reset HEAD~ 
Enter fullscreen mode Exit fullscreen mode

Step 2:

# Make the changes as necessary
Enter fullscreen mode Exit fullscreen mode

Step 3:

git add .
Enter fullscreen mode Exit fullscreen mode

Step 4:

git commit -c ORIG_HEAD
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay