All commands

git restore

Undo changes in your working tree or index — surgically.

What it does

git restore brings back file contents from somewhere else: from the index, from HEAD, or any commit. It's the file-scoped half of the old checkout, with zero branch-switching ambiguity. Discard edits, or unstage — cleanly, by path.

Working Tree

files on disk

files restored
src/bug.jsM
back out of the index

Index · Staging

.git/index

staged
src/bug.jsA

Repository

objects/ → commits

committed history

restore copies file blobs back from the index or HEAD into the working tree

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 3

Step 1

Messed up a file

Your working copy of src/bug.js is broken. Restore rewrites it from the index (or HEAD).

git restore src/bug.js

Working Tree

files on disk

files restored
src/bug.jsM
back out of the index

Index · Staging

.git/index

staged
src/bug.jsA

Repository

objects/ → commits

committed history

The index copy is healthy — let's take it back

Under the hood

1

Two directions, one command

`git restore <file>` writes the file from the index over the working copy — discarding your edits. `git restore --staged <file>` writes HEAD's version into the index — unstaging it. Either way it copies a blob to a destination.

2

Like checkout --, but explicit

Restore exists because `git checkout <path>` was the source of countless grand mysteries. Restore separates 'change what I'm on' (switch) from 'change these files' (restore).

3

Any source is fair game

`git restore --source=HEAD~2 file` resurrects the file as it was two commits ago. Restore reads that blob and writes it to the worktree (or index with --staged).

Aliases the pros type

Memorize the git restore concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git restore
AliasWhy people use it
g rest

Restore a file to last commit state.

g ihrs

Unstage. Pro tip: some call it 'ihrs' after a famous config.

g rest --source=HEAD^

Reincarnate a file from the previous commit.

Command anatomy

git restore <path>
--staged

Restore the INDEX version — i.e. unstage the path.

--source=<rev>

Restore from an arbitrary commit instead of HEAD.

--worktree

Restore only the working-tree copy (default interaction).

When to reach for it

You mangled a file and want HEAD's version back, instantly.

You staged a file by accident — restore --staged to unstage just it.

Pulling a single old version of a file out of history with --source.

Pro tip

Naming is the whole game: `git switch` changes branches, `git restore` changes files, and `git reset` changes the branch + index pointer. Three commands, no ambiguity — this modern trio replaces most checkout usage.

Go deeper with