Undo the most recent local commits in Git
Posted by SceDev
Last Updated: February 02, 2024

To undo a recent commit use the following commands.

 

If you want to keep your changes (Changes will return to working directory):

git reset HEAD~

 

If you want to keep your changes (Changes will return to staging):

git reset --soft HEAD^

 

if you don't want to keep the changes (All changes made in the commit will be deleted from staging and the working directory):

git reset --hard HEAD^
Related Content
Git add and commit files
Git add and commit files
SceDev | Feb 04, 2024
How to initialize a new git repo
How to initialize a new git repo
SceDev | Feb 06, 2024
Delete a file from a git repository
Delete a file from a git repository
SceDev | Feb 08, 2024
Git view commit history
Git view commit history
SceDev | Feb 09, 2024