Resetting Commits

23.1 What Resetting Commits Means

Resetting moves HEAD to an earlier commit. Depending on the reset type, Git may also modify the staging area and working directory. This is used only on local commits.

23.2 Soft Reset (--soft)

Moves HEAD backward but keeps changes staged.
1git reset --soft <commit>

Use case:
Edit or combine recent commits
Change commit message or grouping

Example:
1git reset --soft HEAD~1

23.3 Mixed Reset (--mixed) - Default

Moves HEAD backward and unstages changes but keeps file modifications.
1git reset <commit>

or explicitly:
1git reset --mixed <commit>

Use case:
Rework staged files
Reorganize commits

23.4 Hard Reset (--hard)

Moves HEAD backward and discards all changes.
1git reset --hard <commit>

Use case:
Throw away commits and changes completely
⚠️ Irreversible if commits are not backed up.

23.5 Resetting to a Specific Commit

Reset directly using commit hash:
1git reset --hard abc1234

Git history beyond that commit is removed from the current branch.

23.6 Reset vs Revert (Quick Contrast)

Reset rewrites history (local only)
Revert creates a new commit (safe for shared branches)
Never reset commits that have already been pushed to shared branches.

23.7 Safe Usage Rules

Use reset only on local branches
Avoid --hard unless certain
Prefer revert for public history
Backup commit hashes if unsure

23.8 Key Takeaways

git reset moves HEAD backward.
--soft keeps changes staged.
--mixed keeps changes unstaged (default).
--hard deletes commits and changes permanently.
Never reset shared or pushed commits.