Skip to content

Git

Undo Add#

The opposite instruction of add (staging files) is reset (unstaging files). Use git reset FILE to just unstage FILE or git reset to unstage everything.

Example

git add main.py
git reset main.py

Undo Commit#

To undo the last commit without resetting the worktree and index use git reset --soft HEAD^ which is equivalent to git reset --soft HEAD~1

Example

git commit -m "Add something"
git reset --soft HEAD^
git commit -a -c ORIG_HEAD

Soft vs. Mixed vs. Hard Reset#

--soft
uncommit changes, changes are left staged (index).
--mixed (default)
uncommit + unstage changes, changes are left in working tree.
--hard:
uncommit + unstage + delete changes, nothing left.

References#


Last update: 2020-10-03