blob: 0eb766d3598a1168b3ac9249a5f22a2d033b8982 [file] [log] [blame]
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +07001git-restore(1)
2==============
3
4NAME
5----
6git-restore - Restore working tree files
7
8SYNOPSIS
9--------
10[verse]
Alexandr Miloslavskiycfd93762019-12-03 14:02:17 +000011'git restore' [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>...
Alexandr Miloslavskiya9aecc72019-12-03 14:02:18 +000012'git restore' [<options>] [--source=<tree>] [--staged] [--worktree] --pathspec-from-file=<file> [--pathspec-file-nul]
Alexandr Miloslavskiycfd93762019-12-03 14:02:17 +000013'git restore' (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [--] [<pathspec>...]
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +070014
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
Eric Sunshine088018e2020-05-05 03:17:16 -040025By default, if `--staged` is given, the contents are restored from `HEAD`,
26otherwise from the index. Use `--source` to restore from a different commit.
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +070027
28See "Reset, restore and revert" in linkgit:git[1] for the differences
29between the three commands.
30
Nguyễn Thái Ngọc Duy4e43b7f2019-04-25 16:46:00 +070031THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
32
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +070033OPTIONS
34-------
35-s <tree>::
36--source=<tree>::
37 Restore the working tree files with the content from the given
38 tree. It is common to specify the source tree by naming a
39 commit, branch or tag associated with it.
40+
Eric Sunshine088018e2020-05-05 03:17:16 -040041If not specified, the contents are restored from `HEAD` if `--staged` is
42given, otherwise from the index.
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +070043
44-p::
45--patch::
46 Interactively select hunks in the difference between the
47 restore source and the restore location. See the ``Interactive
48 Mode'' section of linkgit:git-add[1] to learn how to operate
49 the `--patch` mode.
50+
51Note that `--patch` can accept no pathspec and will prompt to restore
52all modified paths.
53
54-W::
55--worktree::
56-S::
57--staged::
58 Specify the restore location. If neither option is specified,
59 by default the working tree is restored. Specifying `--staged`
60 will only restore the index. Specifying both restores both.
61
62-q::
63--quiet::
64 Quiet, suppress feedback messages. Implies `--no-progress`.
65
66--progress::
67--no-progress::
68 Progress status is reported on the standard error stream
69 by default when it is attached to a terminal, unless `--quiet`
70 is specified. This flag enables progress reporting even if not
71 attached to a terminal, regardless of `--quiet`.
72
73--ours::
74--theirs::
75 When restoring files in the working tree from the index, use
76 stage #2 ('ours') or #3 ('theirs') for unmerged paths.
77+
78Note that during `git rebase` and `git pull --rebase`, 'ours' and
79'theirs' may appear swapped. See the explanation of the same options
80in linkgit:git-checkout[1] for details.
81
82-m::
83--merge::
84 When restoring files on the working tree from the index,
85 recreate the conflicted merge in the unmerged paths.
86
87--conflict=<style>::
88 The same as `--merge` option above, but changes the way the
89 conflicting hunks are presented, overriding the
90 `merge.conflictStyle` configuration variable. Possible values
91 are "merge" (default) and "diff3" (in addition to what is
92 shown by "merge" style, shows the original contents).
93
94--ignore-unmerged::
95 When restoring files on the working tree from the index, do
96 not abort the operation if there are unmerged entries and
97 neither `--ours`, `--theirs`, `--merge` or `--conflict` is
98 specified. Unmerged paths on the working tree are left alone.
99
100--ignore-skip-worktree-bits::
101 In sparse checkout mode, by default is to only update entries
102 matched by `<pathspec>` and sparse patterns in
103 $GIT_DIR/info/sparse-checkout. This option ignores the sparse
104 patterns and unconditionally restores any files in
105 `<pathspec>`.
106
107--overlay::
108--no-overlay::
109 In overlay mode, the command never removes files when
110 restoring. In no-overlay mode, tracked files that do not
111 appear in the `--source` tree are removed, to make them match
112 `<tree>` exactly. The default is no-overlay mode.
113
Alexandr Miloslavskiya9aecc72019-12-03 14:02:18 +0000114--pathspec-from-file=<file>::
115 Pathspec is passed in `<file>` instead of commandline args. If
116 `<file>` is exactly `-` then standard input is used. Pathspec
117 elements are separated by LF or CR/LF. Pathspec elements can be
118 quoted as explained for the configuration variable `core.quotePath`
119 (see linkgit:git-config[1]). See also `--pathspec-file-nul` and
120 global `--literal-pathspecs`.
121
122--pathspec-file-nul::
123 Only meaningful with `--pathspec-from-file`. Pathspec elements are
124 separated with NUL character and all other characters are taken
125 literally (including newlines and quotes).
126
Alexandr Miloslavskiycfd93762019-12-03 14:02:17 +0000127\--::
128 Do not interpret any more arguments as options.
129
130<pathspec>...::
131 Limits the paths affected by the operation.
132+
133For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
134
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +0700135EXAMPLES
136--------
137
138The following sequence switches to the `master` branch, reverts the
139`Makefile` to two revisions back, deletes hello.c by mistake, and gets
140it back from the index.
141
142------------
143$ git switch master
144$ git restore --source master~2 Makefile <1>
145$ rm -f hello.c
146$ git restore hello.c <2>
147------------
148
149<1> take a file out of another commit
150<2> restore hello.c from the index
151
152If you want to restore _all_ C source files to match the version in
153the index, you can say
154
155------------
156$ git restore '*.c'
157------------
158
159Note the quotes around `*.c`. The file `hello.c` will also be
160restored, even though it is no longer in the working tree, because the
161file globbing is used to match entries in the index (not in the
162working tree by the shell).
163
164To restore all files in the current directory
165
166------------
167$ git restore .
168------------
169
170or to restore all working tree files with 'top' pathspec magic (see
171linkgit:gitglossary[7])
172
173------------
174$ git restore :/
175------------
176
177To restore a file in the index to match the version in `HEAD` (this is
178the same as using linkgit:git-reset[1])
179
180------------
181$ git restore --staged hello.c
182------------
183
184or you can restore both the index and the working tree (this the same
185as using linkgit:git-checkout[1])
186
187------------
188$ git restore --source=HEAD --staged --worktree hello.c
189------------
190
191or the short form which is more practical but less readable:
192
193------------
194$ git restore -s@ -SW hello.c
195------------
196
197SEE ALSO
198--------
199linkgit:git-checkout[1],
200linkgit:git-reset[1]
201
202GIT
203---
204Part of the linkgit:git[1] suite