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