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.44.0.rc1.17.g3e0d3cd5c7
10 .TH "GIT\-RESTORE" "1" "2024\-02\-15" "Git 2\&.44\&.0\&.rc1\&.17\&.g3" "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\&. This option cannot be used when checking out paths from a tree\-ish (i\&.e\&. with the
119 \fBgit pull \-\-rebase\fR,
123 may appear swapped\&. See the explanation of the same options in
124 \fBgit-checkout\fR(1)
130 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
139 option above, but changes the way the conflicting hunks are presented, overriding the
140 \fBmerge\&.conflictStyle\fR
141 configuration variable\&. Possible values are "merge" (default), "diff3", and "zdiff3"\&.
146 When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
152 is specified\&. Unmerged paths on the working tree are left alone\&.
155 \-\-ignore\-skip\-worktree\-bits
157 In sparse checkout mode, the default is to only update entries matched by
159 and sparse patterns in $GIT_DIR/info/sparse\-checkout\&. This option ignores the sparse patterns and unconditionally restores any files in
163 \-\-recurse\-submodules, \-\-no\-recurse\-submodules
167 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
168 \fB\-\-no\-recurse\-submodules\fR) is used, submodules working trees will not be updated\&. Just like
169 \fBgit-checkout\fR(1), this will detach
174 \-\-overlay, \-\-no\-overlay
176 In overlay mode, the command never removes files when restoring\&. In no\-overlay mode, tracked files that do not appear in the
178 tree are removed, to make them match
180 exactly\&. The default is no\-overlay mode\&.
183 \-\-pathspec\-from\-file=<file>
185 Pathspec is passed in
187 instead of commandline args\&. If
191 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
192 \fBcore\&.quotePath\fR
194 \fBgit-config\fR(1))\&. See also
195 \fB\-\-pathspec\-file\-nul\fR
197 \fB\-\-literal\-pathspecs\fR\&.
200 \-\-pathspec\-file\-nul
203 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
208 Do not interpret any more arguments as options\&.
213 Limits the paths affected by the operation\&.
215 For more details, see the
218 \fBgitglossary\fR(7)\&.
222 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\&.
229 $ git restore \-\-source master~2 Makefile \fB(1)\fR
231 $ git restore hello\&.c \fB(2)\fR
239 r lw(\n(.lu*75u/100u).
241 take a file out of another commit
244 restore hello\&.c from the index
248 If you want to restore \fIall\fR C source files to match the version in the index, you can say
254 $ 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
276 or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
289 To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
295 $ git restore \-\-staged hello\&.c
302 or you can restore both the index and the working tree (this is the same as using \fBgit-checkout\fR(1))
308 $ git restore \-\-source=HEAD \-\-staged \-\-worktree hello\&.c
315 or the short form which is more practical but less readable:
321 $ git restore \-s@ \-SW hello\&.c
329 \fBgit-checkout\fR(1), \fBgit-reset\fR(1)
332 Part of the \fBgit\fR(1) suite