Skip to content
rajin

21Reset, revert and amend

intermediate25–30 minHandbook pp. 47–48 Not started

Warm-up · from “Rebasing and interactive rebasing”

Why do IDs generally change after rebase?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A commit is wrong. The right undo method depends on whether history is shared and whether your uncommitted work must survive.

After this lesson you can

  • Predict soft, mixed and hard reset.

  • Choose revert for shared history.

  • Use amend responsibly.

Key terms

Full glossary

Say what each term means, then open it to check.

  • HEAD · from lesson 14

    Current symbolic branch reference or detached commit identity.

  • Index · from lesson 9

    Prepared path-to-object entries, plus metadata and conflict stages.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Tree · from lesson 6

    Directory snapshot mapping names, modes and object IDs.

Visual mental model

  1. softHEAD
  2. mixedHEAD + Index
  3. hardHEAD + Index + working tree

Build the mental model

Commit-level git reset TARGET moves the current branch (or detached HEAD) to TARGET. --soft leaves Index and disk unchanged. --mixed (default) also updates the Index from TARGET while leaving disk alone. --hard updates the Index and working tree to match TARGET, discarding conflicting tracked changes and potentially removing untracked paths that obstruct tracked files. Path-level reset behaves differently and does not move HEAD.

SimulationWhat each reset mode moves

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

Use git revert COMMIT to create a new commit that reverses a selected change, preserving shared history. git commit --amend replaces the tip using the prepared Index and updated message/metadata. Soft and mixed reset are not universally safe: they still rewrite the current ref and mixed reset replaces staging choices. Check status, preserve uncommitted work separately and create a backup ref before rewriting.

Common mistake · important nuance

A backup branch protects commits, not unstaged work. A hard reset can lose data not stored anywhere; run it only in this disposable lab.

Move between parts freely. Completion counts only what you verify and answer.