<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
<head>\r
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
-<meta name="generator" content="AsciiDoc 7.0.1" />\r
+<meta name="generator" content="AsciiDoc 7.0.2" />\r
<style type="text/css">\r
/* Debug borders */\r
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
<h2>NAME</h2>\r
<div class="sectionbody">\r
<p>git-checkout -\r
- Checkout and switch to a branch.\r
+ Checkout and switch to a branch\r
</p>\r
</div>\r
</div>\r
<h2>SYNOPSIS</h2>\r
<div class="sectionbody">\r
-<p><em>git-checkout</em> [-f] [-b <new_branch>] [<branch>] [<paths>…]</p>\r
+<div class="verseblock">\r
+<div class="content"><em>git-checkout</em> [-f] [-b <new_branch>] [-m] [<branch>]\r
+<em>git-checkout</em> [-m] [<branch>] <paths>…</div></div>\r
</div>\r
<h2>DESCRIPTION</h2>\r
<div class="sectionbody">\r
-<p>When <paths> are not given, this command switches branches, by\r
+<p>When <paths> are not given, this command switches branches by\r
updating the index and working tree to reflect the specified\r
branch, <branch>, and updating HEAD to be <branch> or, if\r
-specified, <new_branch>.</p>\r
+specified, <new_branch>. Using -b will cause <new_branch> to\r
+be created.</p>\r
<p>When <paths> are given, this command does <strong>not</strong> switch\r
branches. It updates the named paths in the working tree from\r
the index file (i.e. it runs <tt>git-checkout-index -f -u</tt>). In\r
</dt>\r
<dd>\r
<p>\r
- Force an re-read of everything.\r
+ Force a re-read of everything.\r
</p>\r
</dd>\r
<dt>\r
</p>\r
</dd>\r
<dt>\r
+-m\r
+</dt>\r
+<dd>\r
+<p>\r
+ If you have local modifications to one or more files that\r
+ are different between the current branch and the branch to\r
+ which you are switching, the command refuses to switch\r
+ branches in order to preserve your modifications in context.\r
+ However, with this option, a three-way merge between the current\r
+ branch, your working tree contents, and the new branch\r
+ is done, and you will be on the new branch.\r
+</p>\r
+<p>When a merge conflict happens, the index entries for conflicting\r
+paths are left unmerged, and you need to resolve the conflicts\r
+and mark the resolved paths with <tt>git update-index</tt>.</p>\r
+</dd>\r
+<dt>\r
<new_branch>\r
</dt>\r
<dd>\r
</dd>\r
</dl>\r
</div>\r
-<h2>EXAMPLE</h2>\r
+<h2>EXAMPLES</h2>\r
<div class="sectionbody">\r
-<p>The following sequence checks out the <tt>master</tt> branch, reverts\r
+<ol>\r
+<li>\r
+<p>\r
+The following sequence checks out the <tt>master</tt> branch, reverts\r
the <tt>Makefile</tt> to two revisions back, deletes hello.c by\r
-mistake, and gets it back from the index.</p>\r
+mistake, and gets it back from the index.\r
+</p>\r
<div class="listingblock">\r
<div class="content">\r
<pre><tt>$ git checkout master <b>(1)</b>\r
<div class="content">\r
<pre><tt>$ git checkout -- hello.c</tt></pre>\r
</div></div>\r
+</li>\r
+<li>\r
+<p>\r
+After working in a wrong branch, switching to the correct\r
+branch would be done using:\r
+</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ git checkout mytopic</tt></pre>\r
+</div></div>\r
+<p>However, your "wrong" branch and correct "mytopic" branch may\r
+differ in files that you have locally modified, in which case,\r
+the above checkout would fail like this:</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ git checkout mytopic\r
+fatal: Entry 'frotz' not uptodate. Cannot merge.</tt></pre>\r
+</div></div>\r
+<p>You can give the <tt>-m</tt> flag to the command, which would try a\r
+three-way merge:</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ git checkout -m mytopic\r
+Auto-merging frotz</tt></pre>\r
+</div></div>\r
+<p>After this three-way merge, the local modifications are _not_\r
+registered in your index file, so <tt>git diff</tt> would show you what\r
+changes you made since the tip of the new branch.</p>\r
+</li>\r
+<li>\r
+<p>\r
+When a merge conflict happens during switching branches with\r
+the <tt>-m</tt> option, you would see something like this:\r
+</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ git checkout -m mytopic\r
+Auto-merging frotz\r
+merge: warning: conflicts during merge\r
+ERROR: Merge conflict in frotz\r
+fatal: merge program failed</tt></pre>\r
+</div></div>\r
+<p>At this point, <tt>git diff</tt> shows the changes cleanly merged as in\r
+the previous example, as well as the changes in the conflicted\r
+files. Edit and resolve the conflict and mark it resolved with\r
+<tt>git update-index</tt> as usual:</p>\r
+<div class="listingblock">\r
+<div class="content">\r
+<pre><tt>$ edit frotz\r
+$ git update-index frotz</tt></pre>\r
+</div></div>\r
+</li>\r
+</ol>\r
</div>\r
<h2>Author</h2>\r
<div class="sectionbody">\r
</div>\r
<div id="footer">\r
<div id="footer-text">\r
-Last updated 27-Dec-2005 00:15:51 PDT\r
+Last updated 18-Mar-2006 07:45:34 UTC\r
</div>\r
</div>\r
</body>\r