1GIT-RESTORE(1) Git Manual GIT-RESTORE(1)
2
3
4
6 git-restore - Restore working tree files
7
9 git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
10 git restore [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
11 git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]
12
14 Restore specified paths in the working tree with some contents from a
15 restore source. If a path is tracked but does not exist in the restore
16 source, it will be removed to match the source.
17
18 The command can also be used to restore the content in the index with
19 --staged, or restore both the working tree and the index with --staged
20 --worktree.
21
22 By default, if --staged is given, the contents are restored from HEAD,
23 otherwise from the index. Use --source to restore from a different
24 commit.
25
26 See "Reset, restore and revert" in git(1) for the differences between
27 the three commands.
28
29 THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
30
32 -s <tree>, --source=<tree>
33 Restore the working tree files with the content from the given
34 tree. It is common to specify the source tree by naming a commit,
35 branch or tag associated with it.
36
37 If not specified, the contents are restored from HEAD if --staged
38 is given, otherwise from the index.
39
40 As a special case, you may use "A...B" as a shortcut for the merge
41 base of A and B if there is exactly one merge base. You can leave
42 out at most one of A and B, in which case it defaults to HEAD.
43
44 -p, --patch
45 Interactively select hunks in the difference between the restore
46 source and the restore location. See the “Interactive Mode” section
47 of git-add(1) to learn how to operate the --patch mode.
48
49 Note that --patch can accept no pathspec and will prompt to restore
50 all modified paths.
51
52 -W, --worktree, -S, --staged
53 Specify the restore location. If neither option is specified, by
54 default the working tree is restored. Specifying --staged will only
55 restore the index. Specifying both restores both.
56
57 -q, --quiet
58 Quiet, suppress feedback messages. Implies --no-progress.
59
60 --progress, --no-progress
61 Progress status is reported on the standard error stream by default
62 when it is attached to a terminal, unless --quiet is specified.
63 This flag enables progress reporting even if not attached to a
64 terminal, regardless of --quiet.
65
66 --ours, --theirs
67 When restoring files in the working tree from the index, use stage
68 #2 (ours) or #3 (theirs) for unmerged paths. This option cannot be
69 used when checking out paths from a tree-ish (i.e. with the
70 --source option).
71
72 Note that during git rebase and git pull --rebase, ours and theirs
73 may appear swapped. See the explanation of the same options in git-
74 checkout(1) for details.
75
76 -m, --merge
77 When restoring files on the working tree from the index, recreate
78 the conflicted merge in the unmerged paths. This option cannot be
79 used when checking out paths from a tree-ish (i.e. with the
80 --source option).
81
82 --conflict=<style>
83 The same as --merge option above, but changes the way the
84 conflicting hunks are presented, overriding the merge.conflictStyle
85 configuration variable. Possible values are "merge" (default),
86 "diff3", and "zdiff3".
87
88 --ignore-unmerged
89 When restoring files on the working tree from the index, do not
90 abort the operation if there are unmerged entries and neither
91 --ours, --theirs, --merge or --conflict is specified. Unmerged
92 paths on the working tree are left alone.
93
94 --ignore-skip-worktree-bits
95 In sparse checkout mode, the default is to only update entries
96 matched by <pathspec> and sparse patterns in
97 $GIT_DIR/info/sparse-checkout. This option ignores the sparse
98 patterns and unconditionally restores any files in <pathspec>.
99
100 --recurse-submodules, --no-recurse-submodules
101 If <pathspec> names an active submodule and the restore location
102 includes the working tree, the submodule will only be updated if
103 this option is given, in which case its working tree will be
104 restored to the commit recorded in the superproject, and any local
105 modifications overwritten. If nothing (or --no-recurse-submodules)
106 is used, submodules working trees will not be updated. Just like
107 git-checkout(1), this will detach HEAD of the submodule.
108
109 --overlay, --no-overlay
110 In overlay mode, the command never removes files when restoring. In
111 no-overlay mode, tracked files that do not appear in the --source
112 tree are removed, to make them match <tree> exactly. The default is
113 no-overlay mode.
114
115 --pathspec-from-file=<file>
116 Pathspec is passed in <file> instead of commandline args. If <file>
117 is exactly - then standard input is used. Pathspec elements are
118 separated by LF or CR/LF. Pathspec elements can be quoted as
119 explained for the configuration variable core.quotePath (see git-
120 config(1)). See also --pathspec-file-nul and global
121 --literal-pathspecs.
122
123 --pathspec-file-nul
124 Only meaningful with --pathspec-from-file. Pathspec elements are
125 separated with NUL character and all other characters are taken
126 literally (including newlines and quotes).
127
128 --
129 Do not interpret any more arguments as options.
130
131 <pathspec>...
132 Limits the paths affected by the operation.
133
134 For more details, see the pathspec entry in gitglossary(7).
135
137 The following sequence switches to the master branch, reverts the
138 Makefile to two revisions back, deletes hello.c by mistake, and gets it
139 back from the index.
140
141 $ git switch master
142 $ git restore --source master~2 Makefile [1m(1)
143 $ rm -f hello.c
144 $ git restore hello.c [1m(2)
145
146
147 1. take a file out of another commit
148 2. restore hello.c from the index
149
150 If you want to restore all C source files to match the version in the
151 index, you can say
152
153 $ git restore '*.c'
154
155 Note the quotes around *.c. The file hello.c will also be restored,
156 even though it is no longer in the working tree, because the file
157 globbing is used to match entries in the index (not in the working tree
158 by the shell).
159
160 To restore all files in the current directory
161
162 $ git restore .
163
164 or to restore all working tree files with top pathspec magic (see
165 gitglossary(7))
166
167 $ git restore :/
168
169 To restore a file in the index to match the version in HEAD (this is
170 the same as using git-reset(1))
171
172 $ git restore --staged hello.c
173
174 or you can restore both the index and the working tree (this is the
175 same as using git-checkout(1))
176
177 $ git restore --source=HEAD --staged --worktree hello.c
178
179 or the short form which is more practical but less readable:
180
181 $ git restore -s@ -SW hello.c
182
184 git-checkout(1), git-reset(1)
185
187 Part of the git(1) suite
188
189
190
191Git 2.43.0 11/20/2023 GIT-RESTORE(1)