Skip to content
  • Undoing Changes · Git & GitHub

Undoing Changes

LearnViaNotes @learnvianotes· 1 min read

Resetting states, restoring working directories, and reverting history.

Case 1: Staged changes (Unstaging files)

If you ran git add but decided you aren't ready to commit those files yet, unstage them using:

Shell
# Unstage a specific file
git reset index.html

# Unstage all staged changes
git reset

Case 2: Committed changes (Undoing commits)

If you committed changes locally but want to pull that commit back, you can reset. Git defines three modes of resetting, referencing HEAD~1 (one commit back from active branch point):

Reset ModeImpact on Working DirectoryImpact on Staging AreaLog History
Soft (--soft)Keeps all modified files intactKeeps all staged changes intactMoves commit pointer back
Mixed (Default)Keeps all modified files intactUnstages all changesMoves commit pointer back
Hard (--hard)Deletes all working changesDeletes all staged changesMoves commit pointer back

Running a Hard Reset

Shell
# WARNING: This destroys all uncommitted local modifications permanently
git reset --hard HEAD~1

# Reset to a specific commit hash in history
git reset --hard a1b2c3d

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report