0
0
Gitdevops~10 mins

Difference between reset and revert in Git - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Difference between reset and revert
Start: Commit History
Choose action
reset
Move HEAD
Change branch state
Discard or keep changes
This flow shows how git reset moves the branch pointer to an earlier commit, changing history, while git revert creates a new commit that undoes changes, preserving history.
Execution Sample
Git
git reset --hard HEAD~1
git revert HEAD
Reset moves the branch back one commit discarding changes; revert creates a new commit that undoes the last commit.
Process Table
StepCommandActionBranch HEADWorking DirectoryResult
1Initial stateBranch at commit C3C3Matches C3Ready to reset or revert
2git reset --hard HEAD~1Move HEAD back to C2, discard changesC2Matches C2History changed, C3 no longer on branch
3git revert HEADCreate new commit C4 that undoes C3C4Matches C4History preserved, undo applied as new commit
4ExitNo more commandsC4Matches C4Reset changed history; revert preserved history
💡 Execution stops after reset and revert commands show different effects on branch and history.
Status Tracker
VariableStartAfter resetAfter revert
Branch HEADC3C2C4
Working DirectoryMatches C3Matches C2Matches C4
Key Moments - 3 Insights
Why does 'git reset' change the commit history but 'git revert' does not?
'git reset' moves the branch pointer backward (see execution_table step 2), effectively removing commits from the branch history. 'git revert' adds a new commit that undoes changes (step 3), so history stays intact.
What happens to the working directory after 'git reset --hard'?
The working directory matches the commit HEAD points to after reset (step 2), discarding any changes from the reset commits.
Can 'git revert' be used safely on shared branches?
Yes, because it creates a new commit without rewriting history (step 3), it is safe for shared branches unlike 'git reset' which rewrites history.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the branch HEAD after 'git reset --hard HEAD~1'?
AC4
BC3
CC2
DHEAD~1
💡 Hint
Check the 'Branch HEAD' column at step 2 in the execution_table.
At which step does git create a new commit to undo changes?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look for the step where 'Create new commit' is mentioned in the Action column.
If you want to undo a commit but keep the history intact, which command should you use?
Agit reset --hard
Bgit revert
Cgit checkout
Dgit branch
💡 Hint
Refer to the concept_flow and execution_table showing which command preserves history.
Concept Snapshot
git reset moves the branch pointer to an earlier commit, changing history and optionally discarding changes.
git revert creates a new commit that undoes changes from a previous commit, preserving history.
Use reset for local undo when history rewrite is safe.
Use revert to safely undo changes on shared branches.
Reset affects HEAD and working directory; revert adds a new commit.
Full Transcript
This lesson shows the difference between git reset and git revert by tracing their effects on commit history and working directory. Git reset moves the branch pointer backward, changing history and discarding changes if --hard is used. Git revert creates a new commit that undoes changes from a previous commit, preserving history. The execution table tracks branch HEAD and working directory state after each command. Key moments clarify why reset rewrites history and revert does not, and when to use each safely. Visual quizzes test understanding of branch state and command effects.