'\" t
.\"     Title: git-restore
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 11/17/2025
.\"    Manual: Git Manual
.\"    Source: Git 2.52.0
.\"  Language: English
.\"
.TH "GIT\-RESTORE" "1" "11/17/2025" "Git 2\&.52\&.0" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-restore \- Restore working tree files
.SH "SYNOPSIS"
.sp
.nf
\fBgit\fR \fBrestore\fR [\fI<options>\fR] [\fB\-\-source=\fR\fI<tree>\fR] [\fB\-\-staged\fR] [\fB\-\-worktree\fR] [\fB\-\-\fR] \fI<pathspec>\fR\&...\:
\fBgit\fR \fBrestore\fR [\fI<options>\fR] [\fB\-\-source=\fR\fI<tree>\fR] [\fB\-\-staged\fR] [\fB\-\-worktree\fR] \fB\-\-pathspec\-from\-file=\fR\fI<file>\fR [\fB\-\-pathspec\-file\-nul\fR]
\fBgit\fR \fBrestore\fR (\fB\-p\fR|\fB\-\-patch\fR) [\fI<options>\fR] [\fB\-\-source=\fR\fI<tree>\fR] [\fB\-\-staged\fR] [\fB\-\-worktree\fR] [\fB\-\-\fR] [\fI<pathspec>\fR\&...\:]
.fi
.SH "DESCRIPTION"
.sp
Restore specified paths in the working tree with some contents from a restore source\&. If a path is tracked but does not exist in the restore source, it will be removed to match the source\&.
.sp
The command can also be used to restore the content in the index with \fB\-\-staged\fR, or restore both the working tree and the index with \fB\-\-staged\fR \fB\-\-worktree\fR\&.
.sp
By default, if \fB\-\-staged\fR is given, the contents are restored from \fBHEAD\fR, otherwise from the index\&. Use \fB\-\-source\fR to restore from a different commit\&.
.sp
See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
.SH "OPTIONS"
.PP
\fB\-s\fR \fI<tree>\fR, \fB\-\-source=\fR\fI<tree>\fR
.RS 4
Restore the working tree files with the content from the given tree\&. It is common to specify the source tree by naming a commit, branch or tag associated with it\&.
.sp
If not specified, the contents are restored from
\fBHEAD\fR
if
\fB\-\-staged\fR
is given, otherwise from the index\&.
.sp
As a special case, you may use "\fI<rev\-A>\fR\fB\&.\&.\&.\fR\fI<rev\-B>\fR" as a shortcut for the merge base of
\fI<rev\-A>\fR
and
\fI<rev\-B>\fR
if there is exactly one merge base\&. You can leave out at most one of
\fI<rev\-A>_\fR
and
\fI<rev\-B>\fR, in which case it defaults to
\fBHEAD\fR\&.
.RE
.PP
\fB\-p\fR, \fB\-\-patch\fR
.RS 4
Interactively select hunks in the difference between the restore source and the restore location\&. See the "Interactive Mode" section of
\fBgit-add\fR(1)
to learn how to operate the
\fB\-\-patch\fR
mode\&.
.RE
.PP
\fB\-U\fR\fI<n>\fR, \fB\-\-unified=\fR\fI<n>\fR
.RS 4
Generate diffs with
\fI<n>\fR
lines of context\&. Defaults to
\fBdiff\&.context\fR
or 3 if the config option is unset\&.
.RE
.PP
\fB\-\-inter\-hunk\-context=\fR\fI<n>\fR
.RS 4
Show the context between diff hunks, up to the specified
\fI<number>\fR
of lines, thereby fusing hunks that are close to each other\&. Defaults to
\fBdiff\&.interHunkContext\fR
or 0 if the config option is unset\&.
.RE
.PP
\fB\-W\fR, \fB\-\-worktree\fR, \fB\-S\fR, \fB\-\-staged\fR
.RS 4
Specify the restore location\&. If neither option is specified, by default the working tree is restored\&. Specifying
\fB\-\-staged\fR
will only restore the index\&. Specifying both restores both\&.
.RE
.PP
\fB\-q\fR, \fB\-\-quiet\fR
.RS 4
Quiet, suppress feedback messages\&. Implies
\fB\-\-no\-progress\fR\&.
.RE
.PP
\fB\-\-progress\fR, \fB\-\-no\-progress\fR
.RS 4
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
\fB\-\-quiet\fR
is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
\fB\-\-quiet\fR\&.
.RE
.PP
\fB\-\-ours\fR, \fB\-\-theirs\fR
.RS 4
When restoring files in the working tree from the index, use stage #2 (\fBours\fR) or #3 (\fBtheirs\fR) for unmerged paths\&. This option cannot be used when checking out paths from a tree\-ish (i\&.e\&. with the
\fB\-\-source\fR
option)\&.
.sp
Note that during
\fBgit\fR
\fBrebase\fR
and
\fBgit\fR
\fBpull\fR
\fB\-\-rebase\fR,
\fBours\fR
and
\fBtheirs\fR
may appear swapped\&. See the explanation of the same options in
\fBgit-checkout\fR(1)
for details\&.
.RE
.PP
\fB\-m\fR, \fB\-\-merge\fR
.RS 4
When restoring files on the working tree from the index, recreate the conflicted merge in the unmerged paths\&. This option cannot be used when checking out paths from a tree\-ish (i\&.e\&. with the
\fB\-\-source\fR
option)\&.
.RE
.PP
\fB\-\-conflict=\fR\fI<style>\fR
.RS 4
The same as
\fB\-\-merge\fR
option above, but changes the way the conflicting hunks are presented, overriding the
\fBmerge\&.conflictStyle\fR
configuration variable\&. Possible values are
\fBmerge\fR
(default),
\fBdiff3\fR, and
\fBzdiff3\fR\&.
.RE
.PP
\fB\-\-ignore\-unmerged\fR
.RS 4
When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
\fB\-\-ours\fR,
\fB\-\-theirs\fR,
\fB\-\-merge\fR
or
\fB\-\-conflict\fR
is specified\&. Unmerged paths on the working tree are left alone\&.
.RE
.PP
\fB\-\-ignore\-skip\-worktree\-bits\fR
.RS 4
In sparse checkout mode, the default is to only update entries matched by
\fI<pathspec>\fR
and sparse patterns in
\fB$GIT_DIR/info/sparse\-checkout\fR\&. This option ignores the sparse patterns and unconditionally restores any files in
\fI<pathspec>\fR\&.
.RE
.PP
\fB\-\-recurse\-submodules\fR, \fB\-\-no\-recurse\-submodules\fR
.RS 4
If
\fI<pathspec>\fR
names an active submodule and the restore location includes the working tree, the submodule will only be updated if this option is given, in which case its working tree will be restored to the commit recorded in the superproject, and any local modifications overwritten\&. If nothing (or
\fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
\fBgit-checkout\fR(1), this will detach
\fBHEAD\fR
of the submodule\&.
.RE
.PP
\fB\-\-overlay\fR, \fB\-\-no\-overlay\fR
.RS 4
In overlay mode, never remove files when restoring\&. In no\-overlay mode, remove tracked files that do not appear in the
\fI<tree>\fR
of
\fB\-\-source=\fR\fI<tree>\fR, to make them match
\fI<tree>\fR
exactly\&. The default is no\-overlay mode\&.
.RE
.PP
\fB\-\-pathspec\-from\-file=\fR\fI<file>\fR
.RS 4
Pathspec is passed in
\fI<file>\fR
instead of commandline args\&. If
\fI<file>\fR
is exactly
\fB\-\fR
then standard input is used\&. Pathspec elements are separated by
\fILF\fR
or
\fICR\fR/\fILF\fR\&. Pathspec elements can be quoted as explained for the configuration variable
\fBcore\&.quotePath\fR
(see
\fBgit-config\fR(1))\&. See also
\fB\-\-pathspec\-file\-nul\fR
and global
\fB\-\-literal\-pathspecs\fR\&.
.RE
.PP
\fB\-\-pathspec\-file\-nul\fR
.RS 4
Only meaningful with
\fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with
\fINUL\fR
character and all other characters are taken literally (including newlines and quotes)\&.
.RE
.PP
\fB\-\-\fR
.RS 4
Do not interpret any more arguments as options\&.
.RE
.PP
\fI<pathspec>\fR\&.\&.\&.
.RS 4
Limits the paths affected by the operation\&.
.sp
For more details, see the
\fIpathspec\fR
entry in
\fBgitglossary\fR(7)\&.
.RE
.SH "EXAMPLES"
.sp
The following sequence switches to the \fBmaster\fR branch, reverts the \fBMakefile\fR to two revisions back, deletes \fBhello\&.c\fR by mistake, and gets it back from the index\&.
.sp
.if n \{\
.RS 4
.\}
.nf
$ git switch master
$ git restore \-\-source master~2 Makefile  \fB(1)\fR
$ rm \-f hello\&.c
$ git restore hello\&.c                     \fB(2)\fR
.fi
.if n \{\
.RE
.\}
.sp
.TS
tab(:);
r lw(\n(.lu*75u/100u).
\fB1.\fR\h'-2n':T{
take a file out of another commit
T}
\fB2.\fR\h'-2n':T{
restore
\fBhello\&.c\fR
from the index
T}
.TE
.sp
If you want to restore \fIall\fR C source files to match the version in the index, you can say
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \*(Aq*\&.c\*(Aq
.fi
.if n \{\
.RE
.\}
.sp
Note the quotes around \fB*\&.c\fR\&. The file \fBhello\&.c\fR will also be restored, even though it is no longer in the working tree, because the file globbing is used to match entries in the index (not in the working tree by the shell)\&.
.sp
To restore all files in the current directory
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \&.
.fi
.if n \{\
.RE
.\}
.sp
or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore :/
.fi
.if n \{\
.RE
.\}
.sp
To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-\-staged hello\&.c
.fi
.if n \{\
.RE
.\}
.sp
or you can restore both the index and the working tree (this is the same as using \fBgit-checkout\fR(1))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-\-source=HEAD \-\-staged \-\-worktree hello\&.c
.fi
.if n \{\
.RE
.\}
.sp
or the short form which is more practical but less readable:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-s@ \-SW hello\&.c
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBgit-checkout\fR(1), \fBgit-reset\fR(1)
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
