3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.42.0.rc0
10 .TH "GIT\-RESTORE" "1" "2023\-08\-04" "Git 2\&.42\&.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>\&...]
42 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\&.
44 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\&.
46 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\&.
48 See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
50 THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&.
53 \-s <tree>, \-\-source=<tree>
55 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\&.
57 If not specified, the contents are restored from
61 is given, otherwise from the index\&.
63 As a special case, you may use
65 as a shortcut for the merge base of
69 if there is exactly one merge base\&. You can leave out at most one of
72 \fBB\fR, in which case it defaults to
78 Interactively select hunks in the difference between the restore source and the restore location\&. See the \(lqInteractive Mode\(rq section of
80 to learn how to operate the
86 can accept no pathspec and will prompt to restore all modified paths\&.
89 \-W, \-\-worktree, \-S, \-\-staged
91 Specify the restore location\&. If neither option is specified, by default the working tree is restored\&. Specifying
93 will only restore the index\&. Specifying both restores both\&.
98 Quiet, suppress feedback messages\&. Implies
99 \fB\-\-no\-progress\fR\&.
102 \-\-progress, \-\-no\-progress
104 Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
106 is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
112 When restoring files in the working tree from the index, use stage #2 (\fIours\fR) or #3 (\fItheirs\fR) for unmerged paths\&.
117 \fBgit pull \-\-rebase\fR,
121 may appear swapped\&. See the explanation of the same options in
122 \fBgit-checkout\fR(1)
128 When restoring files on the working tree from the index, recreate the conflicted merge in the unmerged paths\&.
135 option above, but changes the way the conflicting hunks are presented, overriding the
136 \fBmerge\&.conflictStyle\fR
137 configuration variable\&. Possible values are "merge" (default), "diff3", and "zdiff3"\&.
142 When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
148 is specified\&. Unmerged paths on the working tree are left alone\&.
151 \-\-ignore\-skip\-worktree\-bits
153 In sparse checkout mode, by default is to only update entries matched by
155 and sparse patterns in $GIT_DIR/info/sparse\-checkout\&. This option ignores the sparse patterns and unconditionally restores any files in
159 \-\-recurse\-submodules, \-\-no\-recurse\-submodules
163 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
164 \fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
165 \fBgit-checkout\fR(1), this will detach
170 \-\-overlay, \-\-no\-overlay
172 In overlay mode, the command never removes files when restoring\&. In no\-overlay mode, tracked files that do not appear in the
174 tree are removed, to make them match
176 exactly\&. The default is no\-overlay mode\&.
179 \-\-pathspec\-from\-file=<file>
181 Pathspec is passed in
183 instead of commandline args\&. If
187 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
188 \fBcore\&.quotePath\fR
190 \fBgit-config\fR(1))\&. See also
191 \fB\-\-pathspec\-file\-nul\fR
193 \fB\-\-literal\-pathspecs\fR\&.
196 \-\-pathspec\-file\-nul
199 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
204 Do not interpret any more arguments as options\&.
209 Limits the paths affected by the operation\&.
211 For more details, see the
214 \fBgitglossary\fR(7)\&.
218 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\&.
225 $ git restore \-\-source master~2 Makefile \fB(1)\fR
227 $ git restore hello\&.c \fB(2)\fR
235 r lw(\n(.lu*75u/100u).
237 take a file out of another commit
240 restore hello\&.c from the index
244 If you want to restore \fIall\fR C source files to match the version in the index, you can say
250 $ git restore \*(Aq*\&.c\*(Aq
257 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)\&.
259 To restore all files in the current directory
272 or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
285 To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
291 $ git restore \-\-staged hello\&.c
298 or you can restore both the index and the working tree (this the same as using \fBgit-checkout\fR(1))
304 $ 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
325 \fBgit-checkout\fR(1), \fBgit-reset\fR(1)
328 Part of the \fBgit\fR(1) suite