Skip to main content

What is the difference between git restore and git reset?

git restore and git reset are both used to undo changes, but they work at different levels and with different consequences.


git restore - rolling back files

git restore is intended only for working with files.

What it does:

  • undoes changes in the working tree
  • removes files from the staging area (unstage)
  • does not work with the commit history
  • does not change history

Examples:

bash
git restore file.txt # roll back a file in the working directory git restore --staged file.txt # remove a file from the staging area

Used when you need to:

  • undo local changes in a file
  • remove a file from the index before a commit

git reset - rolling back state and history

git reset works with the branch pointer and commits.

What it does:

  • moves the branch pointer (HEAD)
  • can change the staging area
  • can change the working directory
  • can rewrite history

Modes:

bash
git reset --soft # changes only the history git reset --mixed # history + staging area (default) git reset --hard # history + staging area + working directory

Used when you need to:

  • undo a commit
  • roll a branch back
  • completely remove changes

The key difference

Criteriongit restoregit reset
Works with filesYesPartly
Works with commitsNoYes
Changes historyNoYes
Safe for public branchesYesNo
Main purposeundoing changesrolling back state

Short phrasing for an interview

git restore is used to undo changes in files and the staging area without changing history. git reset is used to roll back commits and the branch state, and it can rewrite history.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.