Remove git commit while keeping the changes

Madeesha’s Tech Space
1 min readMar 14, 2018

--

You may need sometimes to remove the recent git commit you have made to the current working branch while preserving the changes locally. fortunately, this is possible with the git.

Before applying the following commands you need to confirm that there is no additional work done in the local. If so you need to stash them first using git stash command.

git reset HEAD~1
git push -f origin master

If you want to revert your last two commits use ‘git reset HEAD~2’.

This way you can revert your last ’n’ number of git commits while preserving the changes locally.

--

--

No responses yet