[Git]: reset

git

09/24/2019


Deleting(undoing) the last commit

1. Undo commit keeping all files staged

BASH
git reset --soft HEAD~

2. Undo commit and un-stage all files

BASH
git reset HEAD~

3. Undo commit and completely remove all changes

BASH
git reset --hard HEAD~

Note

  • HEAD~[Num]: [Num] is the number of commits to go back
    • HEAD: current commit
    • HEAD~1HEAD~: 1 commit before
  • Instead of HEAD~*, you can use commit id by logging with git log --oneline
    • i.e. git reset --soft 858da45

WRITTEN BY

Keeping a record