Skip to main content
Back to command reference
Undoing Changes

git restore

Restore working tree files or staged changes to a previous state

Practical example

bash
git restore src/index.ts          # discard unstaged changes in one file
git restore --staged src/index.ts  # unstage a file (undo git add)
git restore --source=HEAD~1 .      # restore all files to how they were 2 commits ago

Command overview & how it works

A modern command (introduced in Git 2.23) for restoring files to a known state, replacing the confusing dual use of git checkout. Use git restore <file> to revert a file in your working directory back to the last committed state — discarding uncommitted changes. Use git restore --staged <file> to unstage a file (the inverse of git add) without changing the working directory. Use git restore --source=HEAD~1 <file> to restore a file to how it looked two commits ago. Use git restore . to restore all files in the current directory. Unlike git reset, restore operates at the file level and does not move branch pointers. Unlike git checkout, its behavior is predictable and focused — it always restores files, never switches branches.

Chapter 07 · Disaster Recovery Drills

Disaster-proof your Git workflow with the Field Guide

Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.

Learn more

Practical tips

  • Discard uncommitted edits to a single file with git restore <file> — far safer than a blanket reset.
  • Unstage a file with git restore --staged <file>, the inverse of git add.
  • Restore from a specific point with git restore --source=HEAD~1 <file> to bring back an earlier version.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git restore

All guides →

Related commands

More from Undoing Changes