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.305.g4083a6f052
10 .TH "GIT\-RESTORE" "1" "2024-11-20" "Git 2\&.47\&.0\&.305\&.g4083a6" "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\fR \fB\-\-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 "A\fB\&.\&.\&.\fR\fBB\fR" as a shortcut for the merge base of
66 if there is exactly one merge base\&. You can leave out at most one of
69 \fBB\fR, in which case it defaults to
75 Interactively select hunks in the difference between the restore source and the restore location\&. See the
76 \(lqInteractive Mode\(rq
79 to learn how to operate the
85 can accept no pathspec and will prompt to restore all modified paths\&.
88 \-W, \-\-worktree, \-S, \-\-staged
90 Specify the restore location\&. If neither option is specified, by default the working tree is restored\&. Specifying
92 will only restore the index\&. Specifying both restores both\&.
97 Quiet, suppress feedback messages\&. Implies
98 \fB\-\-no\-progress\fR\&.
101 \-\-progress, \-\-no\-progress
103 Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
105 is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
111 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
125 may appear swapped\&. See the explanation of the same options in
126 \fBgit-checkout\fR(1)
132 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
141 option above, but changes the way the conflicting hunks are presented, overriding the
142 \fBmerge\&.conflictStyle\fR
143 configuration variable\&. Possible values are "merge" (default), "diff3", and "zdiff3"\&.
148 When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
154 is specified\&. Unmerged paths on the working tree are left alone\&.
157 \-\-ignore\-skip\-worktree\-bits
159 In sparse checkout mode, the default is to only update entries matched by
161 and sparse patterns in $GIT_DIR/info/sparse\-checkout\&. This option ignores the sparse patterns and unconditionally restores any files in
165 \-\-recurse\-submodules, \-\-no\-recurse\-submodules
169 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
170 \fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
171 \fBgit-checkout\fR(1), this will detach
176 \-\-overlay, \-\-no\-overlay
178 In overlay mode, the command never removes files when restoring\&. In no\-overlay mode, tracked files that do not appear in the
180 tree are removed, to make them match
182 exactly\&. The default is no\-overlay mode\&.
185 \-\-pathspec\-from\-file=<file>
187 Pathspec is passed in
189 instead of commandline args\&. If
193 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
194 \fBcore\&.quotePath\fR
196 \fBgit-config\fR(1))\&. See also
197 \fB\-\-pathspec\-file\-nul\fR
199 \fB\-\-literal\-pathspecs\fR\&.
202 \-\-pathspec\-file\-nul
205 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
210 Do not interpret any more arguments as options\&.
215 Limits the paths affected by the operation\&.
217 For more details, see the
220 \fBgitglossary\fR(7)\&.
224 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\&.
231 $ git restore \-\-source master~2 Makefile \fB(1)\fR
233 $ git restore hello\&.c \fB(2)\fR
241 r lw(\n(.lu*75u/100u).
243 take a file out of another commit
246 restore hello\&.c from the index
250 If you want to restore \fIall\fR C source files to match the version in the index, you can say
256 $ git restore \*(Aq*\&.c\*(Aq
262 Note the quotes around *\&.\fBc\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)\&.
264 To restore all files in the current directory
276 or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
288 To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
294 $ git restore \-\-staged hello\&.c
300 or you can restore both the index and the working tree (this is the same as using \fBgit-checkout\fR(1))
306 $ git restore \-\-source=HEAD \-\-staged \-\-worktree hello\&.c
312 or the short form which is more practical but less readable:
318 $ git restore \-s@ \-SW hello\&.c
325 \fBgit-checkout\fR(1), \fBgit-reset\fR(1)
328 Part of the \fBgit\fR(1) suite