OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / doc / source / en / TortoiseGit / git_doc / git-reset.html.xml
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-reset(1)">\r
5 <articleinfo>\r
6     <title>git-reset(1)</title>\r
7         <indexterm>\r
8                 <primary>git-reset(1)</primary>\r
9         </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-reset - Reset current HEAD to the specified state</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git reset</emphasis> [--mixed | --soft | --hard | --merge] [-q] [&lt;commit&gt;]\r
19 <emphasis>git reset</emphasis> [-q] [&lt;commit&gt;] [--] &lt;paths&gt;&#8230;</literallayout>\r
20 </blockquote>\r
21 </simplesect>\r
22 <simplesect id="_description">\r
23 <title>DESCRIPTION</title>\r
24 <simpara>Sets the current head to the specified commit and optionally resets the\r
25 index and working tree to match.</simpara>\r
26 <simpara>This command is useful if you notice some small error in a recent\r
27 commit (or set of commits) and want to redo that part without showing\r
28 the undo in the history.</simpara>\r
29 <simpara>If you want to undo a commit other than the latest on a branch,\r
30 <xref linkend="git-revert(1)"/> is your friend.</simpara>\r
31 <simpara>The second form with <emphasis>paths</emphasis> is used to revert selected paths in\r
32 the index from a given commit, without moving HEAD.</simpara>\r
33 </simplesect>\r
34 <simplesect id="_options">\r
35 <title>OPTIONS</title>\r
36 <variablelist>\r
37 <varlistentry>\r
38 <term>\r
39 --mixed\r
40 </term>\r
41 <listitem>\r
42 <simpara>\r
43         Resets the index but not the working tree (i.e., the changed files\r
44         are preserved but not marked for commit) and reports what has not\r
45         been updated. This is the default action.\r
46 </simpara>\r
47 </listitem>\r
48 </varlistentry>\r
49 <varlistentry>\r
50 <term>\r
51 --soft\r
52 </term>\r
53 <listitem>\r
54 <simpara>\r
55         Does not touch the index file nor the working tree at all, but\r
56         requires them to be in a good order. This leaves all your changed\r
57         files "Changes to be committed", as <emphasis>git-status</emphasis> would\r
58         put it.\r
59 </simpara>\r
60 </listitem>\r
61 </varlistentry>\r
62 <varlistentry>\r
63 <term>\r
64 --hard\r
65 </term>\r
66 <listitem>\r
67 <simpara>\r
68         Matches the working tree and index to that of the tree being\r
69         switched to. Any changes to tracked files in the working tree\r
70         since &lt;commit&gt; are lost.\r
71 </simpara>\r
72 </listitem>\r
73 </varlistentry>\r
74 <varlistentry>\r
75 <term>\r
76 --merge\r
77 </term>\r
78 <listitem>\r
79 <simpara>\r
80         Resets the index to match the tree recorded by the named commit,\r
81         and updates the files that are different between the named commit\r
82         and the current commit in the working tree.\r
83 </simpara>\r
84 </listitem>\r
85 </varlistentry>\r
86 <varlistentry>\r
87 <term>\r
88 -q\r
89 </term>\r
90 <listitem>\r
91 <simpara>\r
92         Be quiet, only report errors.\r
93 </simpara>\r
94 </listitem>\r
95 </varlistentry>\r
96 <varlistentry>\r
97 <term>\r
98 &lt;commit&gt;\r
99 </term>\r
100 <listitem>\r
101 <simpara>\r
102         Commit to make the current HEAD. If not given defaults to HEAD.\r
103 </simpara>\r
104 </listitem>\r
105 </varlistentry>\r
106 </variablelist>\r
107 </simplesect>\r
108 <simplesect id="_examples">\r
109 <title>Examples</title>\r
110 <variablelist>\r
111 <varlistentry>\r
112 <term>\r
113 Undo a commit and redo\r
114 </term>\r
115 <listitem>\r
116 <literallayout>$ git commit ...\r
117 $ git reset --soft HEAD^      <co id="CO1-1"/>\r
118 $ edit                        <co id="CO1-2"/>\r
119 $ git commit -a -c ORIG_HEAD  <co id="CO1-3"/></literallayout>\r
120 <calloutlist>\r
121 <callout arearefs="CO1-1">\r
122 <simpara>\r
123 This is most often done when you remembered what you\r
124 just committed is incomplete, or you misspelled your commit\r
125 message, or both.  Leaves working tree as it was before "reset".\r
126 </simpara>\r
127 </callout>\r
128 <callout arearefs="CO1-2">\r
129 <simpara>\r
130 Make corrections to working tree files.\r
131 </simpara>\r
132 </callout>\r
133 <callout arearefs="CO1-3">\r
134 <simpara>\r
135 "reset" copies the old head to .git/ORIG_HEAD; redo the\r
136 commit by starting with its log message.  If you do not need to\r
137 edit the message further, you can give -C option instead.\r
138 </simpara>\r
139 <simpara>See also the --amend option to <xref linkend="git-commit(1)"/>.</simpara>\r
140 </callout>\r
141 </calloutlist>\r
142 </listitem>\r
143 </varlistentry>\r
144 <varlistentry>\r
145 <term>\r
146 Undo commits permanently\r
147 </term>\r
148 <listitem>\r
149 <literallayout>$ git commit ...\r
150 $ git reset --hard HEAD~3   <co id="CO2-1"/></literallayout>\r
151 <calloutlist>\r
152 <callout arearefs="CO2-1">\r
153 <simpara>\r
154 The last three commits (HEAD, HEAD^, and HEAD~2) were bad\r
155 and you do not want to ever see them again.  Do <emphasis role="strong">not</emphasis> do this if\r
156 you have already given these commits to somebody else.  (See the\r
157 "RECOVERING FROM UPSTREAM REBASE" section in <xref linkend="git-rebase(1)"/> for\r
158 the implications of doing so.)\r
159 </simpara>\r
160 </callout>\r
161 </calloutlist>\r
162 </listitem>\r
163 </varlistentry>\r
164 <varlistentry>\r
165 <term>\r
166 Undo a commit, making it a topic branch\r
167 </term>\r
168 <listitem>\r
169 <literallayout>$ git branch topic/wip     <co id="CO3-1"/>\r
170 $ git reset --hard HEAD~3  <co id="CO3-2"/>\r
171 $ git checkout topic/wip   <co id="CO3-3"/></literallayout>\r
172 <calloutlist>\r
173 <callout arearefs="CO3-1">\r
174 <simpara>\r
175 You have made some commits, but realize they were premature\r
176 to be in the "master" branch.  You want to continue polishing\r
177 them in a topic branch, so create "topic/wip" branch off of the\r
178 current HEAD.\r
179 </simpara>\r
180 </callout>\r
181 <callout arearefs="CO3-2">\r
182 <simpara>\r
183 Rewind the master branch to get rid of those three commits.\r
184 </simpara>\r
185 </callout>\r
186 <callout arearefs="CO3-3">\r
187 <simpara>\r
188 Switch to "topic/wip" branch and keep working.\r
189 </simpara>\r
190 </callout>\r
191 </calloutlist>\r
192 </listitem>\r
193 </varlistentry>\r
194 <varlistentry>\r
195 <term>\r
196 Undo add\r
197 </term>\r
198 <listitem>\r
199 <literallayout>$ edit                                     <co id="CO4-1"/>\r
200 $ git add frotz.c filfre.c\r
201 $ mailx                                    <co id="CO4-2"/>\r
202 $ git reset                                <co id="CO4-3"/>\r
203 $ git pull git://info.example.com/ nitfol  <co id="CO4-4"/></literallayout>\r
204 <calloutlist>\r
205 <callout arearefs="CO4-1">\r
206 <simpara>\r
207 You are happily working on something, and find the changes\r
208 in these files are in good order.  You do not want to see them\r
209 when you run "git diff", because you plan to work on other files\r
210 and changes with these files are distracting.\r
211 </simpara>\r
212 </callout>\r
213 <callout arearefs="CO4-2">\r
214 <simpara>\r
215 Somebody asks you to pull, and the changes sounds worthy of merging.\r
216 </simpara>\r
217 </callout>\r
218 <callout arearefs="CO4-3">\r
219 <simpara>\r
220 However, you already dirtied the index (i.e. your index does\r
221 not match the HEAD commit).  But you know the pull you are going\r
222 to make does not affect frotz.c nor filfre.c, so you revert the\r
223 index changes for these two files.  Your changes in working tree\r
224 remain there.\r
225 </simpara>\r
226 </callout>\r
227 <callout arearefs="CO4-4">\r
228 <simpara>\r
229 Then you can pull and merge, leaving frotz.c and filfre.c\r
230 changes still in the working tree.\r
231 </simpara>\r
232 </callout>\r
233 </calloutlist>\r
234 </listitem>\r
235 </varlistentry>\r
236 <varlistentry>\r
237 <term>\r
238 Undo a merge or pull\r
239 </term>\r
240 <listitem>\r
241 <literallayout>$ git pull                         <co id="CO5-1"/>\r
242 Auto-merging nitfol\r
243 CONFLICT (content): Merge conflict in nitfol\r
244 Automatic merge failed; fix conflicts and then commit the result.\r
245 $ git reset --hard                 <co id="CO5-2"/>\r
246 $ git pull . topic/branch          <co id="CO5-3"/>\r
247 Updating from 41223... to 13134...\r
248 Fast forward\r
249 $ git reset --hard ORIG_HEAD       <co id="CO5-4"/></literallayout>\r
250 <calloutlist>\r
251 <callout arearefs="CO5-1">\r
252 <simpara>\r
253 Try to update from the upstream resulted in a lot of\r
254 conflicts; you were not ready to spend a lot of time merging\r
255 right now, so you decide to do that later.\r
256 </simpara>\r
257 </callout>\r
258 <callout arearefs="CO5-2">\r
259 <simpara>\r
260 "pull" has not made merge commit, so "git reset --hard"\r
261 which is a synonym for "git reset --hard HEAD" clears the mess\r
262 from the index file and the working tree.\r
263 </simpara>\r
264 </callout>\r
265 <callout arearefs="CO5-3">\r
266 <simpara>\r
267 Merge a topic branch into the current branch, which resulted\r
268 in a fast forward.\r
269 </simpara>\r
270 </callout>\r
271 <callout arearefs="CO5-4">\r
272 <simpara>\r
273 But you decided that the topic branch is not ready for public\r
274 consumption yet.  "pull" or "merge" always leaves the original\r
275 tip of the current branch in ORIG_HEAD, so resetting hard to it\r
276 brings your index file and the working tree back to that state,\r
277 and resets the tip of the branch to that commit.\r
278 </simpara>\r
279 </callout>\r
280 </calloutlist>\r
281 </listitem>\r
282 </varlistentry>\r
283 <varlistentry>\r
284 <term>\r
285 Undo a merge or pull inside a dirty work tree\r
286 </term>\r
287 <listitem>\r
288 <literallayout>$ git pull                         <co id="CO6-1"/>\r
289 Auto-merging nitfol\r
290 Merge made by recursive.\r
291  nitfol                |   20 +++++----\r
292  ...\r
293 $ git reset --merge ORIG_HEAD      <co id="CO6-2"/></literallayout>\r
294 <calloutlist>\r
295 <callout arearefs="CO6-1">\r
296 <simpara>\r
297 Even if you may have local modifications in your\r
298 working tree, you can safely say "git pull" when you know\r
299 that the change in the other branch does not overlap with\r
300 them.\r
301 </simpara>\r
302 </callout>\r
303 <callout arearefs="CO6-2">\r
304 <simpara>\r
305 After inspecting the result of the merge, you may find\r
306 that the change in the other branch is unsatisfactory.  Running\r
307 "git reset --hard ORIG_HEAD" will let you go back to where you\r
308 were, but it will discard your local changes, which you do not\r
309 want.  "git reset --merge" keeps your local changes.\r
310 </simpara>\r
311 </callout>\r
312 </calloutlist>\r
313 </listitem>\r
314 </varlistentry>\r
315 <varlistentry>\r
316 <term>\r
317 Interrupted workflow\r
318 </term>\r
319 <listitem>\r
320 <simpara>Suppose you are interrupted by an urgent fix request while you\r
321 are in the middle of a large change.  The files in your\r
322 working tree are not in any shape to be committed yet, but you\r
323 need to get to the other branch for a quick bugfix.</simpara>\r
324 <literallayout>$ git checkout feature ;# you were working in "feature" branch and\r
325 $ work work work       ;# got interrupted\r
326 $ git commit -a -m "snapshot WIP"                 <co id="CO7-1"/>\r
327 $ git checkout master\r
328 $ fix fix fix\r
329 $ git commit ;# commit with real log\r
330 $ git checkout feature\r
331 $ git reset --soft HEAD^ ;# go back to WIP state  <co id="CO7-2"/>\r
332 $ git reset                                       <co id="CO7-3"/></literallayout>\r
333 <calloutlist>\r
334 <callout arearefs="CO7-1">\r
335 <simpara>\r
336 This commit will get blown away so a throw-away log message is OK.\r
337 </simpara>\r
338 </callout>\r
339 <callout arearefs="CO7-2">\r
340 <simpara>\r
341 This removes the <emphasis>WIP</emphasis> commit from the commit history, and sets\r
342     your working tree to the state just before you made that snapshot.\r
343 </simpara>\r
344 </callout>\r
345 <callout arearefs="CO7-3">\r
346 <simpara>\r
347 At this point the index file still has all the WIP changes you\r
348     committed as <emphasis>snapshot WIP</emphasis>.  This updates the index to show your\r
349     WIP files as uncommitted.\r
350 </simpara>\r
351 <simpara>See also <xref linkend="git-stash(1)"/>.</simpara>\r
352 </callout>\r
353 </calloutlist>\r
354 </listitem>\r
355 </varlistentry>\r
356 <varlistentry>\r
357 <term>\r
358 Reset a single file in the index\r
359 </term>\r
360 <listitem>\r
361 <simpara>Suppose you have added a file to your index, but later decide you do not\r
362 want to add it to your commit. You can remove the file from the index\r
363 while keeping your changes with git reset.</simpara>\r
364 <literallayout>$ git reset -- frotz.c                      <co id="CO8-1"/>\r
365 $ git commit -m "Commit files in index"     <co id="CO8-2"/>\r
366 $ git add frotz.c                           <co id="CO8-3"/></literallayout>\r
367 <calloutlist>\r
368 <callout arearefs="CO8-1">\r
369 <simpara>\r
370 This removes the file from the index while keeping it in the working\r
371     directory.\r
372 </simpara>\r
373 </callout>\r
374 <callout arearefs="CO8-2">\r
375 <simpara>\r
376 This commits all other changes in the index.\r
377 </simpara>\r
378 </callout>\r
379 <callout arearefs="CO8-3">\r
380 <simpara>\r
381 Adds the file to the index again.\r
382 </simpara>\r
383 </callout>\r
384 </calloutlist>\r
385 </listitem>\r
386 </varlistentry>\r
387 </variablelist>\r
388 </simplesect>\r
389 <simplesect id="_author">\r
390 <title>Author</title>\r
391 <simpara>Written by Junio C Hamano &lt;<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>&gt; and Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>\r
392 </simplesect>\r
393 <simplesect id="_documentation">\r
394 <title>Documentation</title>\r
395 <simpara>Documentation by Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>\r
396 </simplesect>\r
397 <simplesect id="_git">\r
398 <title>GIT</title>\r
399 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>\r
400 </simplesect>\r
401 </article>\r