#version control
#git
#git commit
#undo

How to undo recent commits in git

Anonymous

AnonymousJan 04, 2024

In this post, you will learn how to Undo & redo recent commits in git.

1. Undo Last Commit:

If you just want to undo your last commit, you can use:

$ git reset --soft HEAD^

2. Discard Changes:

If you want to completely get rid of the changes introduced in the last commit, you can use:

$ git reset --hard HEAD^

3. Undo Multiple Commits:

$ git reset --hard HEAD~3

If you want undio Multiple commits then you can use HEAD~2,3,4 and so on.

4. Push your changes:

$ git add .                               
$ git commit -c "your message"
$ git push origin <branch-name> 

Happy Coding! ❤️