Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What does git restore do, and how is it different from git checkout for files?

SHORT ANSWER

git restore discards changes in a file or unstages it. It was added in Git 2.23 to split the file-restoring job away from git checkout, which also switched branches and confused beginners.

Explain it simply

Old git checkout did too many jobs: change branches, create branches, and throw away file edits. Git 2.23 split them. git switch handles branches and git restore handles files.

git restore file replaces the working copy with the staged version, so your unstaged edits are gone for good. git restore --staged file only unstages and leaves your edits in place. git restore --source=HEAD~2 file pulls an older version of the file in.

Be careful: discarding unstaged edits cannot be undone, because Git never saved them.

Example

bash
git restore app.js                    # throw away unstaged edits
git restore --staged app.js           # unstage, keep the edits
git restore --source=HEAD~2 app.js    # old version of one file
# old way: git checkout -- app.js

What to say in the interview

"git restore is the modern command for undoing file changes. Plain restore discards unstaged edits, --staged unstages without losing work, and --source brings back a file from another commit. It replaces the file-related uses of git checkout, which now only needs to be remembered for older Git versions."

Common mistakes

  • Running git restore on a file with edits you wanted; unstaged work is not recoverable.

#git#restore#undo

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.