Autogenerated HTML docs for v1.1.4-g9264
[git.git] / git-checkout.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 include::./stylesheets/xhtml11-manpage.css[]\r
230 /* Workarounds for IE6's broken and incomplete CSS2. */\r
231 \r
232 div.sidebar-content {\r
233   background: #ffffee;\r
234   border: 1px solid silver;\r
235   padding: 0.5em;\r
236 }\r
237 div.sidebar-title, div.image-title {\r
238   font-family: sans-serif;\r
239   font-weight: bold;\r
240   margin-top: 0.0em;\r
241   margin-bottom: 0.5em;\r
242 }\r
243 \r
244 div.listingblock div.content {\r
245   border: 1px solid silver;\r
246   background: #f4f4f4;\r
247   padding: 0.5em;\r
248 }\r
249 \r
250 div.quoteblock-content {\r
251   padding-left: 2.0em;\r
252 }\r
253 \r
254 div.exampleblock-content {\r
255   border-left: 2px solid silver;\r
256   padding-left: 0.5em;\r
257 }\r
258 </style>\r
259 <title>git-checkout(1)</title>\r
260 </head>\r
261 <body>\r
262 <div id="header">\r
263 <h1>\r
264 git-checkout(1) Manual Page\r
265 </h1>\r
266 <h2>NAME</h2>\r
267 <div class="sectionbody">\r
268 <p>git-checkout -\r
269    Checkout and switch to a branch.\r
270 </p>\r
271 </div>\r
272 </div>\r
273 <h2>SYNOPSIS</h2>\r
274 <div class="sectionbody">\r
275 <p><em>git-checkout</em> [-f] [-b &lt;new_branch&gt;] [-m] [&lt;branch&gt;] [&lt;paths&gt;&#8230;]</p>\r
276 </div>\r
277 <h2>DESCRIPTION</h2>\r
278 <div class="sectionbody">\r
279 <p>When &lt;paths&gt; are not given, this command switches branches, by\r
280 updating the index and working tree to reflect the specified\r
281 branch, &lt;branch&gt;, and updating HEAD to be &lt;branch&gt; or, if\r
282 specified, &lt;new_branch&gt;.</p>\r
283 <p>When &lt;paths&gt; are given, this command does <strong>not</strong> switch\r
284 branches.  It updates the named paths in the working tree from\r
285 the index file (i.e. it runs <tt>git-checkout-index -f -u</tt>).  In\r
286 this case, <tt>-f</tt> and <tt>-b</tt> options are meaningless and giving\r
287 either of them results in an error.  &lt;branch&gt; argument can be\r
288 used to specify a specific tree-ish to update the index for the\r
289 given paths before updating the working tree.</p>\r
290 </div>\r
291 <h2>OPTIONS</h2>\r
292 <div class="sectionbody">\r
293 <dl>\r
294 <dt>\r
295 -f\r
296 </dt>\r
297 <dd>\r
298 <p>\r
299         Force an re-read of everything.\r
300 </p>\r
301 </dd>\r
302 <dt>\r
303 -b\r
304 </dt>\r
305 <dd>\r
306 <p>\r
307         Create a new branch and start it at &lt;branch&gt;.\r
308 </p>\r
309 </dd>\r
310 <dt>\r
311 -m\r
312 </dt>\r
313 <dd>\r
314 <p>\r
315         If you have local modifications to a file that is\r
316         different between the current branch and the branch you\r
317         are switching to, the command refuses to switch\r
318         branches, to preserve your modifications in context.\r
319         With this option, a three-way merge between the current\r
320         branch, your working tree contents, and the new branch\r
321         is done, and you will be on the new branch.\r
322 </p>\r
323 <p>When a merge conflict happens, the index entries for conflicting\r
324 paths are left unmerged, and you need to resolve the conflicts\r
325 and mark the resolved paths with <tt>git update-index</tt>.</p>\r
326 </dd>\r
327 <dt>\r
328 &lt;new_branch&gt;\r
329 </dt>\r
330 <dd>\r
331 <p>\r
332         Name for the new branch.\r
333 </p>\r
334 </dd>\r
335 <dt>\r
336 &lt;branch&gt;\r
337 </dt>\r
338 <dd>\r
339 <p>\r
340         Branch to checkout; may be any object ID that resolves to a\r
341         commit. Defaults to HEAD.\r
342 </p>\r
343 </dd>\r
344 </dl>\r
345 </div>\r
346 <h2>EXAMPLES</h2>\r
347 <div class="sectionbody">\r
348 <ol>\r
349 <li>\r
350 <p>\r
351 The following sequence checks out the <tt>master</tt> branch, reverts\r
352 the <tt>Makefile</tt> to two revisions back, deletes hello.c by\r
353 mistake, and gets it back from the index.\r
354 </p>\r
355 <div class="listingblock">\r
356 <div class="content">\r
357 <pre><tt>$ git checkout master <b>(1)</b>\r
358 $ git checkout master~2 Makefile <b>(2)</b>\r
359 $ rm -f hello.c\r
360 $ git checkout hello.c <b>(3)</b>\r
361 \r
362 <b>(1)</b> switch branch\r
363 <b>(2)</b> take out a file out of other commit\r
364 <b>(3)</b> or "git checkout -- hello.c", as in the next example.</tt></pre>\r
365 </div></div>\r
366 <p>If you have an unfortunate branch that is named <tt>hello.c</tt>, the\r
367 last step above would be confused as an instruction to switch to\r
368 that branch.  You should instead write:</p>\r
369 <div class="listingblock">\r
370 <div class="content">\r
371 <pre><tt>$ git checkout -- hello.c</tt></pre>\r
372 </div></div>\r
373 </li>\r
374 <li>\r
375 <p>\r
376 After working in a wrong branch, switching to the correct\r
377 branch you would want to is done with:\r
378 </p>\r
379 <div class="listingblock">\r
380 <div class="content">\r
381 <pre><tt>$ git checkout mytopic</tt></pre>\r
382 </div></div>\r
383 <p>However, your "wrong" branch and correct "mytopic" branch may\r
384 differ in files that you have locally modified, in which case,\r
385 the above checkout would fail like this:</p>\r
386 <div class="listingblock">\r
387 <div class="content">\r
388 <pre><tt>$ git checkout mytopic\r
389 fatal: Entry 'frotz' not uptodate. Cannot merge.</tt></pre>\r
390 </div></div>\r
391 <p>You can give the <tt>-m</tt> flag to the command, which would try a\r
392 three-way merge:</p>\r
393 <div class="listingblock">\r
394 <div class="content">\r
395 <pre><tt>$ git checkout -m mytopic\r
396 Auto-merging frotz</tt></pre>\r
397 </div></div>\r
398 <p>After this three-way merge, the local modifications are _not_\r
399 registered in your index file, so <tt>git diff</tt> would show you what\r
400 changes you made since the tip of the new branch.</p>\r
401 </li>\r
402 <li>\r
403 <p>\r
404 When a merge conflict happens during switching branches with\r
405 the <tt>-m</tt> option, you would see something like this:\r
406 </p>\r
407 <div class="listingblock">\r
408 <div class="content">\r
409 <pre><tt>$ git checkout -m mytopic\r
410 Auto-merging frotz\r
411 merge: warning: conflicts during merge\r
412 ERROR: Merge conflict in frotz\r
413 fatal: merge program failed</tt></pre>\r
414 </div></div>\r
415 <p>At this point, <tt>git diff</tt> shows the changes cleanly merged as in\r
416 the previous example, as well as the changes in the conflicted\r
417 files.  Edit and resolve the conflict and mark it resolved with\r
418 <tt>git update-index</tt> as usual:</p>\r
419 <div class="listingblock">\r
420 <div class="content">\r
421 <pre><tt>$ edit frotz\r
422 $ git update-index frotz</tt></pre>\r
423 </div></div>\r
424 </li>\r
425 </ol>\r
426 </div>\r
427 <h2>Author</h2>\r
428 <div class="sectionbody">\r
429 <p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>\r
430 </div>\r
431 <h2>Documentation</h2>\r
432 <div class="sectionbody">\r
433 <p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>\r
434 </div>\r
435 <h2>GIT</h2>\r
436 <div class="sectionbody">\r
437 <p>Part of the <a href="git.html">git(7)</a> suite</p>\r
438 </div>\r
439 <div id="footer">\r
440 <div id="footer-text">\r
441 Last updated 13-Jan-2006 19:58:25 PDT\r
442 </div>\r
443 </div>\r
444 </body>\r
445 </html>\r