3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.47.0.rc0
10 .TH "GIT\-RESTORE" "1" "2024-09-25" "Git 2\&.47\&.0\&.rc0" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-restore \- Restore working tree files
35 \fIgit restore\fR [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] [\-\-] <pathspec>\&...\:
36 \fIgit restore\fR [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] \-\-pathspec\-from\-file=<file> [\-\-pathspec\-file\-nul]
37 \fIgit restore\fR (\-p|\-\-patch) [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] [\-\-] [<pathspec>\&...\:]
41 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\&.
43 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 \-\-worktree\fR\&.
45 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\&.
47 See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
49 THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&.
52 \-s <tree>, \-\-source=<tree>
54 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\&.
56 If not specified, the contents are restored from
60 is given, otherwise from the index\&.
62 As a special case, you may use
64 as a shortcut for the merge base of
68 if there is exactly one merge base\&. You can leave out at most one of
71 \fBB\fR, in which case it defaults to
77 Interactively select hunks in the difference between the restore source and the restore location\&. See the
78 \(lqInteractive Mode\(rq
81 to learn how to operate the
87 can accept no pathspec and will prompt to restore all modified paths\&.
90 \-W, \-\-worktree, \-S, \-\-staged
92 Specify the restore location\&. If neither option is specified, by default the working tree is restored\&. Specifying
94 will only restore the index\&. Specifying both restores both\&.
99 Quiet, suppress feedback messages\&. Implies
100 \fB\-\-no\-progress\fR\&.
103 \-\-progress, \-\-no\-progress
105 Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
107 is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
113 When restoring files in the working tree from the index, use stage #2 (\fIours\fR) or #3 (\fItheirs\fR) for unmerged paths\&. This option cannot be used when checking out paths from a tree\-ish (i\&.e\&. with the
120 \fBgit pull \-\-rebase\fR,
124 may appear swapped\&. See the explanation of the same options in
125 \fBgit-checkout\fR(1)
131 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
140 option above, but changes the way the conflicting hunks are presented, overriding the
141 \fBmerge\&.conflictStyle\fR
142 configuration variable\&. Possible values are "merge" (default), "diff3", and "zdiff3"\&.
147 When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
153 is specified\&. Unmerged paths on the working tree are left alone\&.
156 \-\-ignore\-skip\-worktree\-bits
158 In sparse checkout mode, the default is to only update entries matched by
160 and sparse patterns in $GIT_DIR/info/sparse\-checkout\&. This option ignores the sparse patterns and unconditionally restores any files in
164 \-\-recurse\-submodules, \-\-no\-recurse\-submodules
168 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
169 \fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
170 \fBgit-checkout\fR(1), this will detach
175 \-\-overlay, \-\-no\-overlay
177 In overlay mode, the command never removes files when restoring\&. In no\-overlay mode, tracked files that do not appear in the
179 tree are removed, to make them match
181 exactly\&. The default is no\-overlay mode\&.
184 \-\-pathspec\-from\-file=<file>
186 Pathspec is passed in
188 instead of commandline args\&. If
192 then standard input is used\&. Pathspec elements are separated by LF or CR/LF\&. Pathspec elements can be quoted as explained for the configuration variable
193 \fBcore\&.quotePath\fR
195 \fBgit-config\fR(1))\&. See also
196 \fB\-\-pathspec\-file\-nul\fR
198 \fB\-\-literal\-pathspecs\fR\&.
201 \-\-pathspec\-file\-nul
204 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
209 Do not interpret any more arguments as options\&.
214 Limits the paths affected by the operation\&.
216 For more details, see the
219 \fBgitglossary\fR(7)\&.
223 The following sequence switches to the \fBmaster\fR branch, reverts the \fBMakefile\fR to two revisions back, deletes hello\&.c by mistake, and gets it back from the index\&.
230 $ git restore \-\-source master~2 Makefile \fB(1)\fR
232 $ git restore hello\&.c \fB(2)\fR
240 r lw(\n(.lu*75u/100u).
242 take a file out of another commit
245 restore hello\&.c from the index
249 If you want to restore \fIall\fR C source files to match the version in the index, you can say
255 $ git restore \*(Aq*\&.c\*(Aq
261 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)\&.
263 To restore all files in the current directory
275 or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
287 To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
293 $ git restore \-\-staged hello\&.c
299 or you can restore both the index and the working tree (this is the same as using \fBgit-checkout\fR(1))
305 $ git restore \-\-source=HEAD \-\-staged \-\-worktree hello\&.c
311 or the short form which is more practical but less readable:
317 $ git restore \-s@ \-SW hello\&.c
324 \fBgit-checkout\fR(1), \fBgit-reset\fR(1)
327 Part of the \fBgit\fR(1) suite