Autogenerated HTML docs for v1.4.0-rc2-g5e3a6
[git.git] / howto / revert-branch-rebase.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 7.0.1" />\r
7 <style type="text/css">\r
8 /* Debug borders */\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
10 /*\r
11   border: 1px solid red;\r
12 */\r
13 }\r
14 \r
15 body {\r
16   margin: 1em 5% 1em 5%;\r
17 }\r
18 \r
19 a { color: blue; }\r
20 a:visited { color: fuchsia; }\r
21 \r
22 em {\r
23   font-style: italic;\r
24 }\r
25 \r
26 strong {\r
27   font-weight: bold;\r
28 }\r
29 \r
30 tt {\r
31   color: navy;\r
32 }\r
33 \r
34 h1, h2, h3, h4, h5, h6 {\r
35   color: #527bbd;\r
36   font-family: sans-serif;\r
37   margin-top: 1.2em;\r
38   margin-bottom: 0.5em;\r
39   line-height: 1.3;\r
40 }\r
41 \r
42 h1 {\r
43   border-bottom: 2px solid silver;\r
44 }\r
45 h2 {\r
46   border-bottom: 2px solid silver;\r
47   padding-top: 0.5em;\r
48 }\r
49 \r
50 div.sectionbody {\r
51   font-family: serif;\r
52   margin-left: 0;\r
53 }\r
54 \r
55 hr {\r
56   border: 1px solid silver;\r
57 }\r
58 \r
59 p {\r
60   margin-top: 0.5em;\r
61   margin-bottom: 0.5em;\r
62 }\r
63 \r
64 pre {\r
65   padding: 0;\r
66   margin: 0;\r
67 }\r
68 \r
69 span#author {\r
70   color: #527bbd;\r
71   font-family: sans-serif;\r
72   font-weight: bold;\r
73   font-size: 1.2em;\r
74 }\r
75 span#email {\r
76 }\r
77 span#revision {\r
78   font-family: sans-serif;\r
79 }\r
80 \r
81 div#footer {\r
82   font-family: sans-serif;\r
83   font-size: small;\r
84   border-top: 2px solid silver;\r
85   padding-top: 0.5em;\r
86   margin-top: 4.0em;\r
87 }\r
88 div#footer-text {\r
89   float: left;\r
90   padding-bottom: 0.5em;\r
91 }\r
92 div#footer-badges {\r
93   float: right;\r
94   padding-bottom: 0.5em;\r
95 }\r
96 \r
97 div#preamble,\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
100 div.admonitionblock {\r
101   margin-right: 10%;\r
102   margin-top: 1.5em;\r
103   margin-bottom: 1.5em;\r
104 }\r
105 div.admonitionblock {\r
106   margin-top: 2.5em;\r
107   margin-bottom: 2.5em;\r
108 }\r
109 \r
110 div.content { /* Block element content. */\r
111   padding: 0;\r
112 }\r
113 \r
114 /* Block element titles. */\r
115 div.title, caption.title {\r
116   font-family: sans-serif;\r
117   font-weight: bold;\r
118   text-align: left;\r
119   margin-top: 1.0em;\r
120   margin-bottom: 0.5em;\r
121 }\r
122 div.title + * {\r
123   margin-top: 0;\r
124 }\r
125 \r
126 td div.title:first-child {\r
127   margin-top: 0.0em;\r
128 }\r
129 div.content div.title:first-child {\r
130   margin-top: 0.0em;\r
131 }\r
132 div.content + div.title {\r
133   margin-top: 0.0em;\r
134 }\r
135 \r
136 div.sidebarblock > div.content {\r
137   background: #ffffee;\r
138   border: 1px solid silver;\r
139   padding: 0.5em;\r
140 }\r
141 \r
142 div.listingblock > div.content {\r
143   border: 1px solid silver;\r
144   background: #f4f4f4;\r
145   padding: 0.5em;\r
146 }\r
147 \r
148 div.quoteblock > div.content {\r
149   padding-left: 2.0em;\r
150 }\r
151 div.quoteblock .attribution {\r
152   text-align: right;\r
153 }\r
154 \r
155 div.admonitionblock .icon {\r
156   vertical-align: top;\r
157   font-size: 1.1em;\r
158   font-weight: bold;\r
159   text-decoration: underline;\r
160   color: #527bbd;\r
161   padding-right: 0.5em;\r
162 }\r
163 div.admonitionblock td.content {\r
164   padding-left: 0.5em;\r
165   border-left: 2px solid silver;\r
166 }\r
167 \r
168 div.exampleblock > div.content {\r
169   border-left: 2px solid silver;\r
170   padding: 0.5em;\r
171 }\r
172 \r
173 div.verseblock div.content {\r
174   white-space: pre;\r
175 }\r
176 \r
177 div.imageblock div.content { padding-left: 0; }\r
178 div.imageblock img { border: 1px solid silver; }\r
179 span.image img { border-style: none; }\r
180 \r
181 dl {\r
182   margin-top: 0.8em;\r
183   margin-bottom: 0.8em;\r
184 }\r
185 dt {\r
186   margin-top: 0.5em;\r
187   margin-bottom: 0;\r
188   font-style: italic;\r
189 }\r
190 dd > *:first-child {\r
191   margin-top: 0;\r
192 }\r
193 \r
194 ul, ol {\r
195     list-style-position: outside;\r
196 }\r
197 ol.olist2 {\r
198   list-style-type: lower-alpha;\r
199 }\r
200 \r
201 div.tableblock > table {\r
202   border-color: #527bbd;\r
203   border-width: 3px;\r
204 }\r
205 thead {\r
206   font-family: sans-serif;\r
207   font-weight: bold;\r
208 }\r
209 tfoot {\r
210   font-weight: bold;\r
211 }\r
212 \r
213 div.hlist {\r
214   margin-top: 0.8em;\r
215   margin-bottom: 0.8em;\r
216 }\r
217 td.hlist1 {\r
218   vertical-align: top;\r
219   font-style: italic;\r
220   padding-right: 0.8em;\r
221 }\r
222 td.hlist2 {\r
223   vertical-align: top;\r
224 }\r
225 \r
226 @media print {\r
227   div#footer-badges { display: none; }\r
228 }\r
229 /* Workarounds for IE6's broken and incomplete CSS2. */\r
230 \r
231 div.sidebar-content {\r
232   background: #ffffee;\r
233   border: 1px solid silver;\r
234   padding: 0.5em;\r
235 }\r
236 div.sidebar-title, div.image-title {\r
237   font-family: sans-serif;\r
238   font-weight: bold;\r
239   margin-top: 0.0em;\r
240   margin-bottom: 0.5em;\r
241 }\r
242 \r
243 div.listingblock div.content {\r
244   border: 1px solid silver;\r
245   background: #f4f4f4;\r
246   padding: 0.5em;\r
247 }\r
248 \r
249 div.quoteblock-content {\r
250   padding-left: 2.0em;\r
251 }\r
252 \r
253 div.exampleblock-content {\r
254   border-left: 2px solid silver;\r
255   padding-left: 0.5em;\r
256 }\r
257 </style>\r
258 <title>Reverting an existing commit</title>\r
259 </head>\r
260 <body>\r
261 <div id="header">\r
262 <h1>Reverting an existing commit</h1>\r
263 </div>\r
264 <div id="preamble">\r
265 <div class="sectionbody">\r
266 <p>One of the changes I pulled into the <em>master</em> branch turns out to\r
267 break building GIT with GCC 2.95.  While they were well intentioned\r
268 portability fixes, keeping things working with gcc-2.95 was also\r
269 important.  Here is what I did to revert the change in the <em>master</em>\r
270 branch and to adjust the <em>pu</em> branch, using core GIT tools and\r
271 barebone Porcelain.</p>\r
272 <p>First, prepare a throw-away branch in case I screw things up.</p>\r
273 <div class="listingblock">\r
274 <div class="content">\r
275 <pre><tt>$ git checkout -b revert-c99 master</tt></pre>\r
276 </div></div>\r
277 <p>Now I am on the <em>revert-c99</em> branch.  Let's figure out which commit to\r
278 revert.  I happen to know that the top of the <em>master</em> branch is a\r
279 merge, and its second parent (i.e. foreign commit I merged from) has\r
280 the change I would want to undo.  Further I happen to know that that\r
281 merge introduced 5 commits or so:</p>\r
282 <div class="listingblock">\r
283 <div class="content">\r
284 <pre><tt>$ git show-branch --more=4 master master^2 | head\r
285 * [master] Merge refs/heads/portable from http://www.cs.berkeley....\r
286  ! [master^2] Replace C99 array initializers with code.\r
287 --\r
288 -  [master] Merge refs/heads/portable from http://www.cs.berkeley....\r
289 *+ [master^2] Replace C99 array initializers with code.\r
290 *+ [master^2~1] Replace unsetenv() and setenv() with older putenv().\r
291 *+ [master^2~2] Include sys/time.h in daemon.c.\r
292 *+ [master^2~3] Fix ?: statements.\r
293 *+ [master^2~4] Replace zero-length array decls with [].\r
294 *  [master~1] tutorial note about git branch</tt></pre>\r
295 </div></div>\r
296 <p>The <em>&#8212;more=4</em> above means "after we reach the merge base of refs,\r
297 show until we display four more common commits".  That last commit\r
298 would have been where the "portable" branch was forked from the main\r
299 git.git repository, so this would show everything on both branches\r
300 since then.  I just limited the output to the first handful using\r
301 <em>head</em>.</p>\r
302 <p>Now I know <em>master^2~4</em> (pronounce it as "find the second parent of\r
303 the <em>master</em>, and then go four generations back following the first\r
304 parent") is the one I would want to revert.  Since I also want to say\r
305 why I am reverting it, the <em>-n</em> flag is given to <em>git revert</em>.  This\r
306 prevents it from actually making a commit, and instead <em>git revert</em>\r
307 leaves the commit log message it wanted to use in <em>.msg</em> file:</p>\r
308 <div class="listingblock">\r
309 <div class="content">\r
310 <pre><tt>$ git revert -n master^2~4\r
311 $ cat .msg\r
312 Revert "Replace zero-length array decls with []."\r
313 \r
314 This reverts 6c5f9baa3bc0d63e141e0afc23110205379905a4 commit.\r
315 $ git diff HEAD ;# to make sure what we are reverting makes sense.\r
316 $ make CC=gcc-2.95 clean test ;# make sure it fixed the breakage.\r
317 $ make clean test ;# make sure it did not cause other breakage.</tt></pre>\r
318 </div></div>\r
319 <p>The reverted change makes sense (from reading the <em>diff</em> output), does\r
320 fix the problem (from <em>make CC=gcc-2.95</em> test), and does not cause new\r
321 breakage (from the last <em>make test</em>).  I'm ready to commit:</p>\r
322 <div class="listingblock">\r
323 <div class="content">\r
324 <pre><tt>$ git commit -a -s ;# read .msg into the log,\r
325                     # and explain why I am reverting.</tt></pre>\r
326 </div></div>\r
327 <p>I could have screwed up in any of the above steps, but in the worst\r
328 case I could just have done <em>git checkout master</em> to start over.\r
329 Fortunately I did not have to; what I have in the current branch\r
330 <em>revert-c99</em> is what I want.  So merge that back into <em>master</em>:</p>\r
331 <div class="listingblock">\r
332 <div class="content">\r
333 <pre><tt>$ git checkout master\r
334 $ git resolve master revert-c99 fast ;# this should be a fast forward\r
335 Updating from 10d781b9caa4f71495c7b34963bef137216f86a8 to e3a693c...\r
336  cache.h        |    8 ++++----\r
337  commit.c       |    2 +-\r
338  ls-files.c     |    2 +-\r
339  receive-pack.c |    2 +-\r
340  server-info.c  |    2 +-\r
341  5 files changed, 8 insertions(+), 8 deletions(-)</tt></pre>\r
342 </div></div>\r
343 <p>The <em>fast</em> in the above <em>git resolve</em> is not a magic.  I knew this\r
344 <em>resolve</em> would result in a fast forward merge, and if not, there is\r
345 something very wrong (so I would do <em>git reset</em> on the <em>master</em> branch\r
346 and examine the situation).  When a fast forward merge is done, the\r
347 message parameter to <em>git resolve</em> is discarded, because no new commit\r
348 is created.  You could have said <em>junk</em> or <em>nothing</em> there as well.</p>\r
349 <p>There is no need to redo the test at this point.  We fast forwarded\r
350 and we know <em>master</em> matches <em>revert-c99</em> exactly.  In fact:</p>\r
351 <div class="listingblock">\r
352 <div class="content">\r
353 <pre><tt>$ git diff master..revert-c99</tt></pre>\r
354 </div></div>\r
355 <p>says nothing.</p>\r
356 <p>Then we rebase the <em>pu</em> branch as usual.</p>\r
357 <div class="listingblock">\r
358 <div class="content">\r
359 <pre><tt>$ git checkout pu\r
360 $ git tag pu-anchor pu\r
361 $ git rebase master\r
362 * Applying: Redo "revert" using three-way merge machinery.\r
363 First trying simple merge strategy to cherry-pick.\r
364 Finished one cherry-pick.\r
365 * Applying: Remove git-apply-patch-script.\r
366 First trying simple merge strategy to cherry-pick.\r
367 Simple cherry-pick fails; trying Automatic cherry-pick.\r
368 Removing Documentation/git-apply-patch-script.txt\r
369 Removing git-apply-patch-script\r
370 Finished one cherry-pick.\r
371 * Applying: Document "git cherry-pick" and "git revert"\r
372 First trying simple merge strategy to cherry-pick.\r
373 Finished one cherry-pick.\r
374 * Applying: mailinfo and applymbox updates\r
375 First trying simple merge strategy to cherry-pick.\r
376 Finished one cherry-pick.\r
377 * Applying: Show commits in topo order and name all commits.\r
378 First trying simple merge strategy to cherry-pick.\r
379 Finished one cherry-pick.\r
380 * Applying: More documentation updates.\r
381 First trying simple merge strategy to cherry-pick.\r
382 Finished one cherry-pick.</tt></pre>\r
383 </div></div>\r
384 <p>The temporary tag <em>pu-anchor</em> is me just being careful, in case <em>git\r
385 rebase</em> screws up.  After this, I can do these for sanity check:</p>\r
386 <div class="listingblock">\r
387 <div class="content">\r
388 <pre><tt>$ git diff pu-anchor..pu ;# make sure we got the master fix.\r
389 $ make CC=gcc-2.95 clean test ;# make sure it fixed the breakage.\r
390 $ make clean test ;# make sure it did not cause other breakage.</tt></pre>\r
391 </div></div>\r
392 <p>Everything is in the good order.  I do not need the temporary branch\r
393 nor tag anymore, so remove them:</p>\r
394 <div class="listingblock">\r
395 <div class="content">\r
396 <pre><tt>$ rm -f .git/refs/tags/pu-anchor\r
397 $ git branch -d revert-c99</tt></pre>\r
398 </div></div>\r
399 <p>It was an emergency fix, so we might as well merge it into the\r
400 <em>release candidate</em> branch, although I expect the next release would\r
401 be some days off:</p>\r
402 <div class="listingblock">\r
403 <div class="content">\r
404 <pre><tt>$ git checkout rc\r
405 $ git pull . master\r
406 Packing 0 objects\r
407 Unpacking 0 objects\r
408 \r
409 * committish: e3a693c...        refs/heads/master from .\r
410 Trying to merge e3a693c... into 8c1f5f0... using 10d781b...\r
411 Committed merge 7fb9b7262a1d1e0a47bbfdcbbcf50ce0635d3f8f\r
412  cache.h        |    8 ++++----\r
413  commit.c       |    2 +-\r
414  ls-files.c     |    2 +-\r
415  receive-pack.c |    2 +-\r
416  server-info.c  |    2 +-\r
417  5 files changed, 8 insertions(+), 8 deletions(-)</tt></pre>\r
418 </div></div>\r
419 <p>And the final repository status looks like this:</p>\r
420 <div class="listingblock">\r
421 <div class="content">\r
422 <pre><tt>$ git show-branch --more=1 master pu rc\r
423 ! [master] Revert "Replace zero-length array decls with []."\r
424  ! [pu] git-repack: Add option to repack all objects.\r
425   * [rc] Merge refs/heads/master from .\r
426 ---\r
427  +  [pu] git-repack: Add option to repack all objects.\r
428  +  [pu~1] More documentation updates.\r
429  +  [pu~2] Show commits in topo order and name all commits.\r
430  +  [pu~3] mailinfo and applymbox updates\r
431  +  [pu~4] Document "git cherry-pick" and "git revert"\r
432  +  [pu~5] Remove git-apply-patch-script.\r
433  +  [pu~6] Redo "revert" using three-way merge machinery.\r
434   - [rc] Merge refs/heads/master from .\r
435 ++* [master] Revert "Replace zero-length array decls with []."\r
436   - [rc~1] Merge refs/heads/master from .\r
437 ... [master~1] Merge refs/heads/portable from http://www.cs.berkeley....</tt></pre>\r
438 </div></div>\r
439 </div>\r
440 </div>\r
441 <div id="footer">\r
442 <div id="footer-text">\r
443 Last updated 15-Jan-2006 02:13:35 PDT\r
444 </div>\r
445 </div>\r
446 </body>\r
447 </html>\r