Skip to content

Instantly share code, notes, and snippets.

@aeinbu
Last active April 1, 2026 08:33
Show Gist options
  • Select an option

  • Save aeinbu/dbdd2fbdee37cbb87ce0ebf36404f089 to your computer and use it in GitHub Desktop.

Select an option

Save aeinbu/dbdd2fbdee37cbb87ce0ebf36404f089 to your computer and use it in GitHub Desktop.
Git reset

git reset

  • git reset --soft, any changes are left as staged (or "ready to commit")
  • git reset --mixed, any changes are left as unstaged
  • git reset --hard, any changes are discarded

Example:

git reset --soft HEAD~3

This will move HEAD three commit back, and keeps all changes from the where you where (two commits later) as staged.
If you now do a new commit, you will effectivly have squashed your last three commits.

Example:

git reset --hard

This will discard all pending changes (both staged and unstaged), but not move the HEAD.

Navigating git

Shortcuts for path-specs

  • HEAD is the current commit
  • HEAD^ is the same as HEAD~1, meaning one commit back from current commit
  • HEAD^^ is the same as HEAD~2, meaning two commits back from current commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment