blob: dcf55c61213b374bb4f4938ee4607a4b5ab3f913 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamanoba4b9282008-07-06 05:20:316<meta name="generator" content="AsciiDoc 8.2.5" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
Junio C Hamanoba4b9282008-07-06 05:20:3119a {
20 color: blue;
21 text-decoration: underline;
22}
23a:visited {
24 color: fuchsia;
25}
Junio C Hamano1a4e8412005-12-27 08:17:2326
27em {
28 font-style: italic;
29}
30
31strong {
32 font-weight: bold;
33}
34
35tt {
36 color: navy;
37}
38
39h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
45}
46
Junio C Hamanoba4b9282008-07-06 05:20:3147h1, h2, h3 {
Junio C Hamano1a4e8412005-12-27 08:17:2348 border-bottom: 2px solid silver;
49}
50h2 {
Junio C Hamano1a4e8412005-12-27 08:17:2351 padding-top: 0.5em;
52}
Junio C Hamanoba4b9282008-07-06 05:20:3153h3 {
54 float: left;
55}
56h3 + * {
57 clear: left;
58}
Junio C Hamano1a4e8412005-12-27 08:17:2359
60div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
63}
64
65hr {
66 border: 1px solid silver;
67}
68
69p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
72}
73
74pre {
75 padding: 0;
76 margin: 0;
77}
78
79span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
Junio C Hamanoba4b9282008-07-06 05:20:3183 font-size: 1.1em;
Junio C Hamano1a4e8412005-12-27 08:17:2384}
85span#email {
86}
87span#revision {
88 font-family: sans-serif;
89}
90
91div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
97}
98div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
101}
102div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
105}
106
107div#preamble,
108div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
114}
115div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
118}
119
120div.content { /* Block element content. */
121 padding: 0;
122}
123
124/* Block element titles. */
125div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
131}
132div.title + * {
133 margin-top: 0;
134}
135
136td div.title:first-child {
137 margin-top: 0.0em;
138}
139div.content div.title:first-child {
140 margin-top: 0.0em;
141}
142div.content + div.title {
143 margin-top: 0.0em;
144}
145
146div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
150}
151
Junio C Hamanoba4b9282008-07-06 05:20:31152div.listingblock {
153 margin-right: 0%;
154}
Junio C Hamano1a4e8412005-12-27 08:17:23155div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
159}
160
161div.quoteblock > div.content {
162 padding-left: 2.0em;
163}
Junio C Hamanoba4b9282008-07-06 05:20:31164
165div.attribution {
Junio C Hamano1a4e8412005-12-27 08:17:23166 text-align: right;
167}
Junio C Hamanoba4b9282008-07-06 05:20:31168div.verseblock + div.attribution {
169 text-align: left;
170}
Junio C Hamano1a4e8412005-12-27 08:17:23171
172div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
179}
180div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
183}
184
185div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
188}
189
190div.verseblock div.content {
191 white-space: pre;
192}
193
194div.imageblock div.content { padding-left: 0; }
195div.imageblock img { border: 1px solid silver; }
196span.image img { border-style: none; }
197
198dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
201}
202dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
206}
207dd > *:first-child {
208 margin-top: 0;
209}
210
211ul, ol {
212 list-style-position: outside;
213}
Junio C Hamanoba4b9282008-07-06 05:20:31214div.olist2 ol {
Junio C Hamano1a4e8412005-12-27 08:17:23215 list-style-type: lower-alpha;
216}
217
218div.tableblock > table {
Junio C Hamanoba4b9282008-07-06 05:20:31219 border: 3px solid #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23220}
221thead {
222 font-family: sans-serif;
223 font-weight: bold;
224}
225tfoot {
226 font-weight: bold;
227}
228
229div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
232}
Junio C Hamanoba4b9282008-07-06 05:20:31233div.hlist td {
234 padding-bottom: 5px;
235}
Junio C Hamano1a4e8412005-12-27 08:17:23236td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
240}
241td.hlist2 {
242 vertical-align: top;
243}
244
245@media print {
246 div#footer-badges { display: none; }
247}
Junio C Hamanoba4b9282008-07-06 05:20:31248
249div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
256}
257
258div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
261}
262div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
265}
266div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
269}
270div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
273}
274include1::./stylesheets/xhtml11-manpage.css[]
Junio C Hamano1a4e8412005-12-27 08:17:23275/* Workarounds for IE6's broken and incomplete CSS2. */
276
277div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
281}
282div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
287}
288
289div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
293}
294
295div.quoteblock-content {
296 padding-left: 2.0em;
297}
298
299div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
302}
Junio C Hamanoba4b9282008-07-06 05:20:31303
304/* IE6 sets dynamically generated links as visited. */
305div#toc a:visited { color: blue; }
Junio C Hamano1a4e8412005-12-27 08:17:23306</style>
307<title>git-checkout(1)</title>
308</head>
309<body>
310<div id="header">
311<h1>
312git-checkout(1) Manual Page
313</h1>
314<h2>NAME</h2>
315<div class="sectionbody">
316<p>git-checkout -
Junio C Hamanoa14a4032008-03-25 09:11:02317 Checkout a branch or paths to the working tree
Junio C Hamano1a4e8412005-12-27 08:17:23318</p>
319</div>
320</div>
321<h2>SYNOPSIS</h2>
322<div class="sectionbody">
Junio C Hamano2b135272006-03-18 07:45:42323<div class="verseblock">
Junio C Hamano5cf43ca2008-08-20 09:14:14324<div class="content"><em>git checkout</em> [-q] [-f] [--track | --no-track] [-b &lt;new_branch&gt; [-l]] [-m] [&lt;branch&gt;]
Junio C Hamanoa476efa2008-10-10 15:31:42325<em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] [--] &lt;paths&gt;&#8230;</div></div>
Junio C Hamano1a4e8412005-12-27 08:17:23326</div>
Junio C Hamanoba4b9282008-07-06 05:20:31327<h2 id="_description">DESCRIPTION</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23328<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31329<div class="para"><p>When &lt;paths&gt; are not given, this command switches branches by
Junio C Hamano1a4e8412005-12-27 08:17:23330updating the index and working tree to reflect the specified
331branch, &lt;branch&gt;, and updating HEAD to be &lt;branch&gt; or, if
Junio C Hamano2b135272006-03-18 07:45:42332specified, &lt;new_branch&gt;. Using -b will cause &lt;new_branch&gt; to
Junio C Hamano103ad7f2007-03-14 11:19:26333be created; in this case you can use the --track or --no-track
Junio C Hamanoba4b9282008-07-06 05:20:31334options, which will be passed to <tt>git branch</tt>.</p></div>
Junio C Hamano5cf43ca2008-08-20 09:14:14335<div class="para"><p>As a convenience, --track will default to create a branch whose
336name is constructed from the specified branch name by stripping
337the first namespace level.</p></div>
Junio C Hamanoba4b9282008-07-06 05:20:31338<div class="para"><p>When &lt;paths&gt; are given, this command does <strong>not</strong> switch
Junio C Hamano1a4e8412005-12-27 08:17:23339branches. It updates the named paths in the working tree from
Junio C Hamanoa476efa2008-10-10 15:31:42340the index file, or from a named commit. In
341this case, the <tt>-b</tt> options is meaningless and giving
Junio C Hamano8f62db92007-02-01 00:22:22342either of them results in an error. &lt;tree-ish&gt; argument can be
343used to specify a specific tree-ish (i.e. commit, tag or tree)
344to update the index for the given paths before updating the
Junio C Hamanoba4b9282008-07-06 05:20:31345working tree.</p></div>
Junio C Hamanoa476efa2008-10-10 15:31:42346<div class="para"><p>The index may contain unmerged entries after a failed merge. By
347default, if you try to check out such an entry from the index, the
348checkout operation will fail and nothing will be checked out.
349Using -f will ignore these unmerged entries. The contents from a
350specific side of the merge can be checked out of the index by
351using --ours or --theirs. With -m, changes made to the working tree
352file can be discarded to recreate the original conflicted merge result.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23353</div>
Junio C Hamanoba4b9282008-07-06 05:20:31354<h2 id="_options">OPTIONS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23355<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31356<div class="vlist"><dl>
Junio C Hamano1a4e8412005-12-27 08:17:23357<dt>
Junio C Hamano39381a72007-02-02 07:35:15358-q
359</dt>
360<dd>
361<p>
Junio C Hamanocae86272007-08-21 02:20:49362 Quiet, suppress feedback messages.
Junio C Hamano39381a72007-02-02 07:35:15363</p>
364</dd>
365<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23366-f
367</dt>
368<dd>
369<p>
Junio C Hamanoa476efa2008-10-10 15:31:42370 When switching branches, proceed even if the index or the
371 working tree differs from HEAD. This is used to throw away
372 local changes.
373</p>
374<div class="para"><p>When checking out paths from the index, do not fail upon unmerged
375entries; instead, unmerged entries are ignored.</p></div>
376</dd>
377<dt>
378--ours
379</dt>
380<dt>
381--theirs
382</dt>
383<dd>
384<p>
385 When checking out paths from the index, check out stage #2
386 (<em>ours</em>) or #3 (<em>theirs</em>) for unmerged paths.
Junio C Hamano1a4e8412005-12-27 08:17:23387</p>
388</dd>
389<dt>
390-b
391</dt>
392<dd>
393<p>
Junio C Hamanob2f5edd2006-05-21 10:50:09394 Create a new branch named &lt;new_branch&gt; and start it at
395 &lt;branch&gt;. The new branch name must pass all checks defined
396 by <a href="git-check-ref-format.html">git-check-ref-format(1)</a>. Some of these checks
397 may restrict the characters allowed in a branch name.
Junio C Hamano1a4e8412005-12-27 08:17:23398</p>
399</dd>
400<dt>
Junio C Hamanoeb415992008-06-08 22:49:47401-t
402</dt>
403<dt>
404--track
Junio C Hamano103ad7f2007-03-14 11:19:26405</dt>
406<dd>
407<p>
Junio C Hamanoba4b9282008-07-06 05:20:31408 When creating a new branch, set up configuration so that <em>git-pull</em>
Junio C Hamano24bc09a2008-02-28 00:27:44409 will automatically retrieve data from the start point, which must be
410 a branch. Use this if you always pull from the same upstream branch
411 into the new branch, and if you don't want to use "git pull
412 &lt;repository&gt; &lt;refspec&gt;" explicitly. This behavior is the default
413 when the start point is a remote branch. Set the
414 branch.autosetupmerge configuration variable to <tt>false</tt> if you want
Junio C Hamanoba4b9282008-07-06 05:20:31415 <em>git-checkout</em> and <em>git-branch</em> to always behave as if <em>--no-track</em> were
Junio C Hamano24bc09a2008-02-28 00:27:44416 given. Set it to <tt>always</tt> if you want this behavior when the
417 start-point is either a local or remote branch.
Junio C Hamano103ad7f2007-03-14 11:19:26418</p>
Junio C Hamano043628e2008-08-24 03:34:11419<div class="para"><p>If no <em>-b</em> option was given, the name of the new branch will be
420derived from the remote branch, by attempting to guess the name
421of the branch on remote system. If "remotes/" or "refs/remotes/"
422are prefixed, it is stripped away, and then the part up to the
423next slash (which would be the nickname of the remote) is removed.
424This would tell us to use "hack" as the local branch when branching
425off of "origin/hack" (or "remotes/origin/hack", or even
426"refs/remotes/origin/hack"). If the given name has no slash, or the above
427guessing results in an empty name, the guessing is aborted. You can
428exlicitly give a name with <em>-b</em> in such a case.</p></div>
Junio C Hamano103ad7f2007-03-14 11:19:26429</dd>
430<dt>
431--no-track
432</dt>
433<dd>
434<p>
Junio C Hamano24bc09a2008-02-28 00:27:44435 Ignore the branch.autosetupmerge configuration variable.
Junio C Hamano103ad7f2007-03-14 11:19:26436</p>
437</dd>
438<dt>
Junio C Hamano341071d2006-06-04 07:24:48439-l
440</dt>
441<dd>
442<p>
Junio C Hamano1d90cb02007-07-03 07:05:31443 Create the new branch's reflog. This activates recording of
444 all changes made to the branch ref, enabling use of date
445 based sha1 expressions such as "&lt;branchname&gt;@{yesterday}".
Junio C Hamano341071d2006-06-04 07:24:48446</p>
447</dd>
448<dt>
Junio C Hamano74e8a2d2006-01-14 03:58:41449-m
450</dt>
Junio C Hamanoa476efa2008-10-10 15:31:42451<dt>
452--merge
453</dt>
Junio C Hamano74e8a2d2006-01-14 03:58:41454<dd>
455<p>
Junio C Hamanoa476efa2008-10-10 15:31:42456 When switching branches,
457 if you have local modifications to one or more files that
Junio C Hamano2b135272006-03-18 07:45:42458 are different between the current branch and the branch to
459 which you are switching, the command refuses to switch
460 branches in order to preserve your modifications in context.
461 However, with this option, a three-way merge between the current
Junio C Hamano74e8a2d2006-01-14 03:58:41462 branch, your working tree contents, and the new branch
463 is done, and you will be on the new branch.
464</p>
Junio C Hamanoba4b9282008-07-06 05:20:31465<div class="para"><p>When a merge conflict happens, the index entries for conflicting
Junio C Hamano74e8a2d2006-01-14 03:58:41466paths are left unmerged, and you need to resolve the conflicts
Junio C Hamano89d4e0f2007-02-18 00:34:59467and mark the resolved paths with <tt>git add</tt> (or <tt>git rm</tt> if the merge
Junio C Hamanoba4b9282008-07-06 05:20:31468should result in deletion of the path).</p></div>
Junio C Hamanoa476efa2008-10-10 15:31:42469<div class="para"><p>When checking out paths from the index, this option lets you recreate
470the conflicted merge in the specified paths.</p></div>
471</dd>
472<dt>
473--conflict=&lt;style&gt;
474</dt>
475<dd>
476<p>
477 The same as --merge option above, but changes the way the
478 conflicting hunks are presented, overriding the
479 merge.conflictstyle configuration variable. Possible values are
480 "merge" (default) and "diff3" (in addition to what is shown by
481 "merge" style, shows the original contents).
482</p>
Junio C Hamano74e8a2d2006-01-14 03:58:41483</dd>
484<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23485&lt;new_branch&gt;
486</dt>
487<dd>
488<p>
489 Name for the new branch.
490</p>
491</dd>
492<dt>
493&lt;branch&gt;
494</dt>
495<dd>
496<p>
497 Branch to checkout; may be any object ID that resolves to a
Junio C Hamano4f9a6052007-01-17 20:25:16498 commit. Defaults to HEAD.
Junio C Hamano1a4e8412005-12-27 08:17:23499</p>
Junio C Hamanoba4b9282008-07-06 05:20:31500<div class="para"><p>When this parameter names a non-branch (but still a valid commit object),
501your HEAD becomes <em>detached</em>.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23502</dd>
Junio C Hamanoba4b9282008-07-06 05:20:31503</dl></div>
Junio C Hamano1a4e8412005-12-27 08:17:23504</div>
Junio C Hamanoba4b9282008-07-06 05:20:31505<h2 id="_detached_head">Detached HEAD</h2>
Junio C Hamano4f9a6052007-01-17 20:25:16506<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31507<div class="para"><p>It is sometimes useful to be able to <em>checkout</em> a commit that is
Junio C Hamano4f9a6052007-01-17 20:25:16508not at the tip of one of your branches. The most obvious
509example is to check out the commit at a tagged official release
Junio C Hamanoba4b9282008-07-06 05:20:31510point, like this:</p></div>
Junio C Hamano4f9a6052007-01-17 20:25:16511<div class="listingblock">
512<div class="content">
513<pre><tt>$ git checkout v2.6.18</tt></pre>
514</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31515<div class="para"><p>Earlier versions of git did not allow this and asked you to
Junio C Hamano4f9a6052007-01-17 20:25:16516create a temporary branch using <tt>-b</tt> option, but starting from
517version 1.5.0, the above command <em>detaches</em> your HEAD from the
518current branch and directly point at the commit named by the tag
Junio C Hamanoba4b9282008-07-06 05:20:31519(<tt>v2.6.18</tt> in the above example).</p></div>
520<div class="para"><p>You can use usual git commands while in this state. You can use
Junio C Hamanofce7c7e2008-07-02 03:06:38521<tt>git reset --hard $othercommit</tt> to further move around, for
Junio C Hamano4f9a6052007-01-17 20:25:16522example. You can make changes and create a new commit on top of
523a detached HEAD. You can even create a merge by using <tt>git
Junio C Hamanoba4b9282008-07-06 05:20:31524merge $othercommit</tt>.</p></div>
525<div class="para"><p>The state you are in while your HEAD is detached is not recorded
Junio C Hamano4f9a6052007-01-17 20:25:16526by any branch (which is natural --- you are not on any branch).
527What this means is that you can discard your temporary commits
528and merges by switching back to an existing branch (e.g. <tt>git
529checkout master</tt>), and a later <tt>git prune</tt> or <tt>git gc</tt> would
Junio C Hamano9d52e572007-02-13 23:48:20530garbage-collect them. If you did this by mistake, you can ask
Junio C Hamanoba4b9282008-07-06 05:20:31531the reflog for HEAD where you were, e.g.</p></div>
Junio C Hamano9d52e572007-02-13 23:48:20532<div class="listingblock">
533<div class="content">
534<pre><tt>$ git log -g -2 HEAD</tt></pre>
535</div></div>
Junio C Hamano4f9a6052007-01-17 20:25:16536</div>
Junio C Hamanoba4b9282008-07-06 05:20:31537<h2 id="_examples">EXAMPLES</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23538<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31539<div class="olist"><ol>
Junio C Hamano74e8a2d2006-01-14 03:58:41540<li>
541<p>
542The following sequence checks out the <tt>master</tt> branch, reverts
Junio C Hamano1a4e8412005-12-27 08:17:23543the <tt>Makefile</tt> to two revisions back, deletes hello.c by
Junio C Hamano74e8a2d2006-01-14 03:58:41544mistake, and gets it back from the index.
545</p>
Junio C Hamano1a4e8412005-12-27 08:17:23546<div class="listingblock">
547<div class="content">
Junio C Hamanoc8d88c22006-04-29 07:02:01548<pre><tt>$ git checkout master <b>(1)</b>
549$ git checkout master~2 Makefile <b>(2)</b>
Junio C Hamano1a4e8412005-12-27 08:17:23550$ rm -f hello.c
Junio C Hamanoc8d88c22006-04-29 07:02:01551$ git checkout hello.c <b>(3)</b></tt></pre>
Junio C Hamano1a4e8412005-12-27 08:17:23552</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31553<div class="colist"><ol>
Junio C Hamanoc8d88c22006-04-29 07:02:01554<li>
555<p>
556switch branch
557</p>
558</li>
559<li>
560<p>
561take out a file out of other commit
562</p>
563</li>
564<li>
565<p>
566restore hello.c from HEAD of current branch
567</p>
Junio C Hamanoba4b9282008-07-06 05:20:31568<div class="para"><p>If you have an unfortunate branch that is named <tt>hello.c</tt>, this
Junio C Hamanoc8d88c22006-04-29 07:02:01569step would be confused as an instruction to switch to that branch.
Junio C Hamanoba4b9282008-07-06 05:20:31570You should instead write:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23571<div class="listingblock">
572<div class="content">
573<pre><tt>$ git checkout -- hello.c</tt></pre>
574</div></div>
Junio C Hamano74e8a2d2006-01-14 03:58:41575</li>
Junio C Hamanoba4b9282008-07-06 05:20:31576</ol></div>
Junio C Hamanoc8d88c22006-04-29 07:02:01577</li>
Junio C Hamano74e8a2d2006-01-14 03:58:41578<li>
579<p>
580After working in a wrong branch, switching to the correct
Junio C Hamano2b135272006-03-18 07:45:42581branch would be done using:
Junio C Hamano74e8a2d2006-01-14 03:58:41582</p>
583<div class="listingblock">
584<div class="content">
585<pre><tt>$ git checkout mytopic</tt></pre>
586</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31587<div class="para"><p>However, your "wrong" branch and correct "mytopic" branch may
Junio C Hamano74e8a2d2006-01-14 03:58:41588differ in files that you have locally modified, in which case,
Junio C Hamanoba4b9282008-07-06 05:20:31589the above checkout would fail like this:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:41590<div class="listingblock">
591<div class="content">
592<pre><tt>$ git checkout mytopic
593fatal: Entry 'frotz' not uptodate. Cannot merge.</tt></pre>
594</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31595<div class="para"><p>You can give the <tt>-m</tt> flag to the command, which would try a
596three-way merge:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:41597<div class="listingblock">
598<div class="content">
599<pre><tt>$ git checkout -m mytopic
600Auto-merging frotz</tt></pre>
601</div></div>
Junio C Hamano4604fe52008-09-19 06:37:10602<div class="para"><p>After this three-way merge, the local modifications are _not_
Junio C Hamano74e8a2d2006-01-14 03:58:41603registered in your index file, so <tt>git diff</tt> would show you what
Junio C Hamanoba4b9282008-07-06 05:20:31604changes you made since the tip of the new branch.</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:41605</li>
606<li>
607<p>
608When a merge conflict happens during switching branches with
609the <tt>-m</tt> option, you would see something like this:
610</p>
611<div class="listingblock">
612<div class="content">
613<pre><tt>$ git checkout -m mytopic
614Auto-merging frotz
615merge: warning: conflicts during merge
616ERROR: Merge conflict in frotz
617fatal: merge program failed</tt></pre>
618</div></div>
Junio C Hamanoba4b9282008-07-06 05:20:31619<div class="para"><p>At this point, <tt>git diff</tt> shows the changes cleanly merged as in
Junio C Hamano74e8a2d2006-01-14 03:58:41620the previous example, as well as the changes in the conflicted
621files. Edit and resolve the conflict and mark it resolved with
Junio C Hamanoba4b9282008-07-06 05:20:31622<tt>git add</tt> as usual:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:41623<div class="listingblock">
624<div class="content">
625<pre><tt>$ edit frotz
Junio C Hamano89d4e0f2007-02-18 00:34:59626$ git add frotz</tt></pre>
Junio C Hamano74e8a2d2006-01-14 03:58:41627</div></div>
628</li>
Junio C Hamanoba4b9282008-07-06 05:20:31629</ol></div>
Junio C Hamano1a4e8412005-12-27 08:17:23630</div>
Junio C Hamanoba4b9282008-07-06 05:20:31631<h2 id="_author">Author</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23632<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31633<div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23634</div>
Junio C Hamanoba4b9282008-07-06 05:20:31635<h2 id="_documentation">Documentation</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23636<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31637<div class="para"><p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23638</div>
Junio C Hamanoba4b9282008-07-06 05:20:31639<h2 id="_git">GIT</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23640<div class="sectionbody">
Junio C Hamanoba4b9282008-07-06 05:20:31641<div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:23642</div>
643<div id="footer">
644<div id="footer-text">
Junio C Hamanoa476efa2008-10-10 15:31:42645Last updated 2008-10-10 15:30:41 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23646</div>
647</div>
648</body>
649</html>