Skip to content
BENIBIX Learn

Git Reset

Development🔀 Version ControlUndo Commands

Also known as git reset, git reset --hard, Reset a Branch

Moving a branch back to an earlier commit. Later commits drop out of it.

Think of it like

Think of it like moving a bookmark back a few pages. The pages after it no longer count.

Example

Emma made two messy commits she has not pushed. She runs git reset --soft HEAD~2 and commits again as one.

Why it matters

It cleans up local work before you share it.

Definition

Git reset moves your branch back to an earlier commit. The commits after it drop out of the branch. The soft mode keeps their changes staged. The default, mixed mode keeps the changes in your files but unstaged. The hard mode throws the changes away, and that cannot be undone easily.

Example code

console
$ git reset --soft HEAD~1
$ git status --short
M  index.html
The last commit is gone, but its change is still staged.
Reset moves the branch label back from C to B.

Common mistake

Running git reset --hard without thinking. Changes you never committed are lost for good.

Key takeaways

  1. 1
    Moves the branch. Back to the commit you name.
  2. 2
    Three modes. Soft, mixed or hard.
  3. 3
    Local work only. Never reset what others pulled.

Compare

Learn it properly