Update Git docs to 2.29.2
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-restore.xml
blob895cfcd42c51b44ac62fc8dede9695d650cda98a
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">\r
3 \r
4 <sect2 lang="en" id="git-restore(1)">\r
5     <title>git-restore(1)</title>\r
6 <indexterm>\r
7 <primary>git-restore(1)</primary>\r
8 </indexterm>\r
9 <simplesect id="git-restore(1)__name">\r
10 <title>NAME</title>\r
11 <simpara>git-restore - Restore working tree files</simpara>\r
12 </simplesect>\r
13 <simplesect id="git-restore(1)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <blockquote>\r
16 <literallayout><emphasis>git restore</emphasis> [&lt;options&gt;] [--source=&lt;tree&gt;] [--staged] [--worktree] [--] &lt;pathspec&gt;&#8230;\r
17 <emphasis>git restore</emphasis> [&lt;options&gt;] [--source=&lt;tree&gt;] [--staged] [--worktree] --pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]\r
18 <emphasis>git restore</emphasis> (-p|--patch) [&lt;options&gt;] [--source=&lt;tree&gt;] [--staged] [--worktree] [--] [&lt;pathspec&gt;&#8230;]</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="git-restore(1)__description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Restore specified paths in the working tree with some contents from a\r
24 restore source. If a path is tracked but does not exist in the restore\r
25 source, it will be removed to match the source.</simpara>\r
26 <simpara>The command can also be used to restore the content in the index with\r
27 <emphasis>--staged</emphasis>, or restore both the working tree and the index with\r
28 <emphasis>--staged --worktree</emphasis>.</simpara>\r
29 <simpara>By default, if <emphasis>--staged</emphasis> is given, the contents are restored from <emphasis>HEAD</emphasis>,\r
30 otherwise from the index. Use <emphasis>--source</emphasis> to restore from a different commit.</simpara>\r
31 <simpara>See "Reset, restore and revert" in <xref linkend="git(1)" /> for the differences\r
32 between the three commands.</simpara>\r
33 <simpara>THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.</simpara>\r
34 </simplesect>\r
35 <simplesect id="git-restore(1)__options">\r
36 <title>OPTIONS</title>\r
37 <variablelist>\r
38 <varlistentry>\r
39 <term>\r
40 -s &lt;tree&gt;\r
41 </term>\r
42 <term>\r
43 --source=&lt;tree&gt;\r
44 </term>\r
45 <listitem>\r
46 <simpara>\r
47         Restore the working tree files with the content from the given\r
48         tree. It is common to specify the source tree by naming a\r
49         commit, branch or tag associated with it.\r
50 </simpara>\r
51 <simpara>If not specified, the contents are restored from <emphasis>HEAD</emphasis> if <emphasis>--staged</emphasis> is\r
52 given, otherwise from the index.</simpara>\r
53 </listitem>\r
54 </varlistentry>\r
55 <varlistentry>\r
56 <term>\r
57 -p\r
58 </term>\r
59 <term>\r
60 --patch\r
61 </term>\r
62 <listitem>\r
63 <simpara>\r
64         Interactively select hunks in the difference between the\r
65         restore source and the restore location. See the Interactive\r
66         Mode section of <xref linkend="git-add(1)" /> to learn how to operate\r
67         the <emphasis>--patch</emphasis> mode.\r
68 </simpara>\r
69 <simpara>Note that <emphasis>--patch</emphasis> can accept no pathspec and will prompt to restore\r
70 all modified paths.</simpara>\r
71 </listitem>\r
72 </varlistentry>\r
73 <varlistentry>\r
74 <term>\r
75 -W\r
76 </term>\r
77 <term>\r
78 --worktree\r
79 </term>\r
80 <term>\r
81 -S\r
82 </term>\r
83 <term>\r
84 --staged\r
85 </term>\r
86 <listitem>\r
87 <simpara>\r
88         Specify the restore location. If neither option is specified,\r
89         by default the working tree is restored. Specifying <emphasis>--staged</emphasis>\r
90         will only restore the index. Specifying both restores both.\r
91 </simpara>\r
92 </listitem>\r
93 </varlistentry>\r
94 <varlistentry>\r
95 <term>\r
96 -q\r
97 </term>\r
98 <term>\r
99 --quiet\r
100 </term>\r
101 <listitem>\r
102 <simpara>\r
103         Quiet, suppress feedback messages. Implies <emphasis>--no-progress</emphasis>.\r
104 </simpara>\r
105 </listitem>\r
106 </varlistentry>\r
107 <varlistentry>\r
108 <term>\r
109 --progress\r
110 </term>\r
111 <term>\r
112 --no-progress\r
113 </term>\r
114 <listitem>\r
115 <simpara>\r
116         Progress status is reported on the standard error stream\r
117         by default when it is attached to a terminal, unless <emphasis>--quiet</emphasis>\r
118         is specified. This flag enables progress reporting even if not\r
119         attached to a terminal, regardless of <emphasis>--quiet</emphasis>.\r
120 </simpara>\r
121 </listitem>\r
122 </varlistentry>\r
123 <varlistentry>\r
124 <term>\r
125 --ours\r
126 </term>\r
127 <term>\r
128 --theirs\r
129 </term>\r
130 <listitem>\r
131 <simpara>\r
132         When restoring files in the working tree from the index, use\r
133         stage #2 (<emphasis>ours</emphasis>) or #3 (<emphasis>theirs</emphasis>) for unmerged paths.\r
134 </simpara>\r
135 <simpara>Note that during <emphasis>git rebase</emphasis> and <emphasis>git pull --rebase</emphasis>, <emphasis>ours</emphasis> and\r
136 <emphasis>theirs</emphasis> may appear swapped. See the explanation of the same options\r
137 in <xref linkend="git-checkout(1)" /> for details.</simpara>\r
138 </listitem>\r
139 </varlistentry>\r
140 <varlistentry>\r
141 <term>\r
142 -m\r
143 </term>\r
144 <term>\r
145 --merge\r
146 </term>\r
147 <listitem>\r
148 <simpara>\r
149         When restoring files on the working tree from the index,\r
150         recreate the conflicted merge in the unmerged paths.\r
151 </simpara>\r
152 </listitem>\r
153 </varlistentry>\r
154 <varlistentry>\r
155 <term>\r
156 --conflict=&lt;style&gt;\r
157 </term>\r
158 <listitem>\r
159 <simpara>\r
160         The same as <emphasis>--merge</emphasis> option above, but changes the way the\r
161         conflicting hunks are presented, overriding the\r
162         <emphasis>merge.conflictStyle</emphasis> configuration variable.  Possible values\r
163         are "merge" (default) and "diff3" (in addition to what is\r
164         shown by "merge" style, shows the original contents).\r
165 </simpara>\r
166 </listitem>\r
167 </varlistentry>\r
168 <varlistentry>\r
169 <term>\r
170 --ignore-unmerged\r
171 </term>\r
172 <listitem>\r
173 <simpara>\r
174         When restoring files on the working tree from the index, do\r
175         not abort the operation if there are unmerged entries and\r
176         neither <emphasis>--ours</emphasis>, <emphasis>--theirs</emphasis>, <emphasis>--merge</emphasis> or <emphasis>--conflict</emphasis> is\r
177         specified. Unmerged paths on the working tree are left alone.\r
178 </simpara>\r
179 </listitem>\r
180 </varlistentry>\r
181 <varlistentry>\r
182 <term>\r
183 --ignore-skip-worktree-bits\r
184 </term>\r
185 <listitem>\r
186 <simpara>\r
187         In sparse checkout mode, by default is to only update entries\r
188         matched by <emphasis>&lt;pathspec&gt;</emphasis> and sparse patterns in\r
189         $GIT_DIR/info/sparse-checkout. This option ignores the sparse\r
190         patterns and unconditionally restores any files in\r
191         <emphasis>&lt;pathspec&gt;</emphasis>.\r
192 </simpara>\r
193 </listitem>\r
194 </varlistentry>\r
195 <varlistentry>\r
196 <term>\r
197 --recurse-submodules\r
198 </term>\r
199 <term>\r
200 --no-recurse-submodules\r
201 </term>\r
202 <listitem>\r
203 <simpara>\r
204         If <emphasis>&lt;pathspec&gt;</emphasis> names an active submodule and the restore location\r
205         includes the working tree, the submodule will only be updated if\r
206         this option is given, in which case its working tree will be\r
207         restored to the commit recorded in the superproject, and any local\r
208         modifications overwritten. If nothing (or\r
209         <emphasis>--no-recurse-submodules</emphasis>) is used, submodules working trees will\r
210         not be updated. Just like <xref linkend="git-checkout(1)" />, this will detach\r
211         <emphasis>HEAD</emphasis> of the submodule.\r
212 </simpara>\r
213 </listitem>\r
214 </varlistentry>\r
215 <varlistentry>\r
216 <term>\r
217 --overlay\r
218 </term>\r
219 <term>\r
220 --no-overlay\r
221 </term>\r
222 <listitem>\r
223 <simpara>\r
224         In overlay mode, the command never removes files when\r
225         restoring. In no-overlay mode, tracked files that do not\r
226         appear in the <emphasis>--source</emphasis> tree are removed, to make them match\r
227         <emphasis>&lt;tree&gt;</emphasis> exactly. The default is no-overlay mode.\r
228 </simpara>\r
229 </listitem>\r
230 </varlistentry>\r
231 <varlistentry>\r
232 <term>\r
233 --pathspec-from-file=&lt;file&gt;\r
234 </term>\r
235 <listitem>\r
236 <simpara>\r
237         Pathspec is passed in <emphasis>&lt;file&gt;</emphasis> instead of commandline args. If\r
238         <emphasis>&lt;file&gt;</emphasis> is exactly <emphasis>-</emphasis> then standard input is used. Pathspec\r
239         elements are separated by LF or CR/LF. Pathspec elements can be\r
240         quoted as explained for the configuration variable <emphasis>core.quotePath</emphasis>\r
241         (see <xref linkend="git-config(1)" />). See also <emphasis>--pathspec-file-nul</emphasis> and\r
242         global <emphasis>--literal-pathspecs</emphasis>.\r
243 </simpara>\r
244 </listitem>\r
245 </varlistentry>\r
246 <varlistentry>\r
247 <term>\r
248 --pathspec-file-nul\r
249 </term>\r
250 <listitem>\r
251 <simpara>\r
252         Only meaningful with <emphasis>--pathspec-from-file</emphasis>. Pathspec elements are\r
253         separated with NUL character and all other characters are taken\r
254         literally (including newlines and quotes).\r
255 </simpara>\r
256 </listitem>\r
257 </varlistentry>\r
258 <varlistentry>\r
259 <term>\r
260 --\r
261 </term>\r
262 <listitem>\r
263 <simpara>\r
264         Do not interpret any more arguments as options.\r
265 </simpara>\r
266 </listitem>\r
267 </varlistentry>\r
268 <varlistentry>\r
269 <term>\r
270 &lt;pathspec&gt;&#8230;\r
271 </term>\r
272 <listitem>\r
273 <simpara>\r
274         Limits the paths affected by the operation.\r
275 </simpara>\r
276 <simpara>For more details, see the <emphasis>pathspec</emphasis> entry in <xref linkend="gitglossary(7)" />.</simpara>\r
277 </listitem>\r
278 </varlistentry>\r
279 </variablelist>\r
280 </simplesect>\r
281 <simplesect id="git-restore(1)__examples">\r
282 <title>EXAMPLES</title>\r
283 <simpara>The following sequence switches to the <emphasis>master</emphasis> branch, reverts the\r
284 <emphasis>Makefile</emphasis> to two revisions back, deletes hello.c by mistake, and gets\r
285 it back from the index.</simpara>\r
286 <screen>$ git switch master\r
287 $ git restore --source master~2 Makefile  <co id="git-restore_CO1-1"/>\r
288 $ rm -f hello.c\r
289 $ git restore hello.c                     <co id="git-restore_CO1-2"/></screen>\r
290 <calloutlist>\r
291 <callout arearefs="git-restore_CO1-1">\r
292 <para>\r
293 take a file out of another commit\r
294 </para>\r
295 </callout>\r
296 <callout arearefs="git-restore_CO1-2">\r
297 <para>\r
298 restore hello.c from the index\r
299 </para>\r
300 </callout>\r
301 </calloutlist>\r
302 <simpara>If you want to restore <emphasis>all</emphasis> C source files to match the version in\r
303 the index, you can say</simpara>\r
304 <screen>$ git restore '*.c'</screen>\r
305 <simpara>Note the quotes around <emphasis>*.c</emphasis>.  The file <emphasis>hello.c</emphasis> will also be\r
306 restored, even though it is no longer in the working tree, because the\r
307 file globbing is used to match entries in the index (not in the\r
308 working tree by the shell).</simpara>\r
309 <simpara>To restore all files in the current directory</simpara>\r
310 <screen>$ git restore .</screen>\r
311 <simpara>or to restore all working tree files with <emphasis>top</emphasis> pathspec magic (see\r
312 <xref linkend="gitglossary(7)" />)</simpara>\r
313 <screen>$ git restore :/</screen>\r
314 <simpara>To restore a file in the index to match the version in <emphasis>HEAD</emphasis> (this is\r
315 the same as using <xref linkend="git-reset(1)" />)</simpara>\r
316 <screen>$ git restore --staged hello.c</screen>\r
317 <simpara>or you can restore both the index and the working tree (this the same\r
318 as using <xref linkend="git-checkout(1)" />)</simpara>\r
319 <screen>$ git restore --source=HEAD --staged --worktree hello.c</screen>\r
320 <simpara>or the short form which is more practical but less readable:</simpara>\r
321 <screen>$ git restore -s@ -SW hello.c</screen>\r
322 </simplesect>\r
323 <simplesect id="git-restore(1)__see_also">\r
324 <title>SEE ALSO</title>\r
325 <simpara><xref linkend="git-checkout(1)" />,\r
326 <xref linkend="git-reset(1)" /></simpara>\r
327 </simplesect>\r
328 <simplesect id="git-restore(1)__git">\r
329 <title>GIT</title>\r
330 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
331 </simplesect>\r
332 </sect2>\r