Git: How to Remove a Commit That Has Not Been Pushed to The Remote?

less than a minute of reading

The procedure to remove a change that has been already committed but not pushed to the remote is easy and requires just a single git command to be executed in your terminal.


All you have to do is to type:

git reset HEAD~1

This will reset your state to the previous commit, turning changes you want to remove into staged ones. You can remove them by doing hard reset.

After this your should end up with clean state - git status should output:

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

You're done.



Words: 106
Published in: Git
Last Revision: February 20, 2024

Related Articles   📚