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