Typorithm · hard

reset, revert & reflog

git-reset-refloggitresetrevertreflog
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn reset, revert & reflog

0%

Advanced

reset --soft moves HEAD but keeps changes staged; --hard discards them (destructive). revert creates a NEW commit that undoes a commit, safe for shared history. reflog records where HEAD has been, so you can recover lost commits by resetting to HEAD@{n}.

git reset moves the current branch to point at a different commit. --soft HEAD~1 rewinds one commit but keeps that commit's changes staged, ready to recommit. --hard HEAD~1 rewinds and throws the changes away entirely — destructive and unrecoverable through normal means.

git revert HEAD takes a different approach: instead of rewriting history it adds a NEW commit that applies the inverse of HEAD. Because it never rewrites existing commits, revert is the safe way to undo something already pushed to a shared branch.

git reflog is your safety net. It logs every position HEAD has occupied, addressable as HEAD@{0}, HEAD@{1}, HEAD@{2}, and so on. If a reset or rebase loses a commit, find it in the reflog and git reset --hard HEAD@{2} brings the branch back.

01

reset --soft keeps changes staged; --hard discards them.

02

revert adds a new commit — safe for shared history.

03

reflog tracks HEAD so you can recover lost commits.

git reset --soft HEAD~1
git reset --hard HEAD~1
git revert HEAD
git reflog
git reset --hard HEAD@{2}

Read the implementation

Connect each part of the code to the concept before you type.

1. Soft reset

reset --soft moves HEAD back one commit but keeps that commit's changes staged.

git reset --soft HEAD~1

2. Hard reset

reset --hard moves HEAD and discards the changes — a destructive operation.

git reset --hard HEAD~1

3. Safe undo

revert creates a new commit that undoes HEAD, safe for shared history.

git revert HEAD

4. HEAD history

reflog lists every position HEAD has been at, letting you find lost commits.

git reflog

5. Recover via reflog

HEAD@{2} is where HEAD was two moves ago; resetting to it recovers that state.

git reset --hard HEAD@{2}

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

reset, revert & reflog: Lesson & Practice · Typorithm | ApplyDjinn