Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Intermediate Git: Stashing, Tagging, Reverting, and ResettingLesson 4.4

Resetting History: git reset

git reset --soft, git reset --mixed, git reset --hard, HEAD~, reset vs revert, dangerous commands

Resetting History: git reset

Git reset moves the current branch pointer backward to an earlier commit, effectively discarding everything after that point from the branch history. It is powerful but potentially destructive โ€” use it only on local, unpushed commits.

Diagramgit reset Three Modes Comparison

IMAGE PROMPT (replace this block with your generated image):

Flat three-column mode comparison diagram on white background. Title: git reset: Three Modes Explained. Starting state row at top spanning all columns: commit timeline C1 โ†’ C2 โ†’ C3 (HEAD), with staged and working directory changes shown as icons. Three result columns below, each showing the state after git reset HEAD~1. Column 1: --soft (header: light green fill). Commit pointer moves to C2. Staging area: shows all C3 changes still staged (green file icons with checkmarks). Working directory: unchanged. Use case badge: Combine commits โ€” recommit as one. Column 2: --mixed (default) (header: light amber fill). Commit pointer moves to C2. Staging area: cleared. Working directory: C3 changes still present (orange modified icons). Use case badge: Unstage files, keep changes. Column 3: --hard (header: light red fill, warning icon). Commit pointer moves to C2. Staging area: cleared. Working directory: cleared โ€” all C3 changes gone (gray empty icons). Use case badge: red warning โ€” Discard all changes permanently. Recovery note at bottom: git reflog can recover lost commits within 30 days. Brand color #3A5EFF for column headers border accents. White background.

The Three Modes of Reset

--soft: Moves the branch pointer back but keeps all changes staged. Your work is preserved and ready to be re-committed.

git reset --soft HEAD~1

--mixed (default): Moves the branch pointer back and unstages changes, but keeps them in the working directory.

git reset HEAD~1

--hard: Moves the branch pointer back and discards all changes in both the staging area and working directory. This cannot be easily undone.

git reset --hard HEAD~1

Practical Use Cases

Use --soft to combine several commits into one by resetting back and re-committing everything together. Use --mixed to unstage files without losing your changes. Use --hard with extreme caution โ€” only when you truly want to discard all recent work.

Recovering from Hard Reset

Even after a hard reset, commits are not immediately deleted. Git keeps them for 30 days in the reflog:

git reflog
git reset --hard abc1234

Find the lost commit's hash in the reflog and reset to it.

Up next

Cherry-Picking Commits

Sign in to track progress

Resetting History: git reset โ€” Intermediate Git: Stashing, Tagging, Reverting, and Resetting โ€” Git and GitHub Complete Course: From Beginner to Advanced โ€” Script Valley โ€” Script Valley