Skip to content
Author: ytianle (58.33%), ytianle (41.67%)

Cancel Commit⚓︎

This guide helps you cancel your last Git commit.

Remove Commit but Keep Changes⚓︎

If you want to cancel your last commit but keep the changes:

terminal
git reset --soft HEAD~1 # (1)
  1. HEAD~1 refers to the commit before the last one. --soft option keeps your changes in the staging area.

Remove Commit and discard Changes⚓︎

terminal
git reset --hard HEAD~1 # (2)
  1. --hard option discards all changes in the working directory and staging area.

Remove Commit but Keep Changes in Working Directory⚓︎

terminal
git reset HEAD~1 # (3)
  1. By default, it is --mixed which unstages changes but keeps them in the working directory. Theoretically, it resets the index to HEAD and does not affect the working tree.

Command line resource: Git Reset Documentation