| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | <!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 Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 8.2.5" /> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | <style type="text/css"> |
| 8 | /* Debug borders */ |
| 9 | p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { |
| 10 | /* |
| 11 | border: 1px solid red; |
| 12 | */ |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | margin: 1em 5% 1em 5%; |
| 17 | } |
| 18 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 19 | a { |
| 20 | color: blue; |
| 21 | text-decoration: underline; |
| 22 | } |
| 23 | a:visited { |
| 24 | color: fuchsia; |
| 25 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 | |
| 27 | em { |
| 28 | font-style: italic; |
| 29 | } |
| 30 | |
| 31 | strong { |
| 32 | font-weight: bold; |
| 33 | } |
| 34 | |
| 35 | tt { |
| 36 | color: navy; |
| 37 | } |
| 38 | |
| 39 | h1, 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 Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 47 | h1, h2, h3 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 48 | border-bottom: 2px solid silver; |
| 49 | } |
| 50 | h2 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 51 | padding-top: 0.5em; |
| 52 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 53 | h3 { |
| 54 | float: left; |
| 55 | } |
| 56 | h3 + * { |
| 57 | clear: left; |
| 58 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 59 | |
| 60 | div.sectionbody { |
| 61 | font-family: serif; |
| 62 | margin-left: 0; |
| 63 | } |
| 64 | |
| 65 | hr { |
| 66 | border: 1px solid silver; |
| 67 | } |
| 68 | |
| 69 | p { |
| 70 | margin-top: 0.5em; |
| 71 | margin-bottom: 0.5em; |
| 72 | } |
| 73 | |
| 74 | pre { |
| 75 | padding: 0; |
| 76 | margin: 0; |
| 77 | } |
| 78 | |
| 79 | span#author { |
| 80 | color: #527bbd; |
| 81 | font-family: sans-serif; |
| 82 | font-weight: bold; |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 83 | font-size: 1.1em; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | } |
| 85 | span#email { |
| 86 | } |
| 87 | span#revision { |
| 88 | font-family: sans-serif; |
| 89 | } |
| 90 | |
| 91 | div#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 | } |
| 98 | div#footer-text { |
| 99 | float: left; |
| 100 | padding-bottom: 0.5em; |
| 101 | } |
| 102 | div#footer-badges { |
| 103 | float: right; |
| 104 | padding-bottom: 0.5em; |
| 105 | } |
| 106 | |
| 107 | div#preamble, |
| 108 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 109 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 110 | div.admonitionblock { |
| 111 | margin-right: 10%; |
| 112 | margin-top: 1.5em; |
| 113 | margin-bottom: 1.5em; |
| 114 | } |
| 115 | div.admonitionblock { |
| 116 | margin-top: 2.5em; |
| 117 | margin-bottom: 2.5em; |
| 118 | } |
| 119 | |
| 120 | div.content { /* Block element content. */ |
| 121 | padding: 0; |
| 122 | } |
| 123 | |
| 124 | /* Block element titles. */ |
| 125 | div.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 | } |
| 132 | div.title + * { |
| 133 | margin-top: 0; |
| 134 | } |
| 135 | |
| 136 | td div.title:first-child { |
| 137 | margin-top: 0.0em; |
| 138 | } |
| 139 | div.content div.title:first-child { |
| 140 | margin-top: 0.0em; |
| 141 | } |
| 142 | div.content + div.title { |
| 143 | margin-top: 0.0em; |
| 144 | } |
| 145 | |
| 146 | div.sidebarblock > div.content { |
| 147 | background: #ffffee; |
| 148 | border: 1px solid silver; |
| 149 | padding: 0.5em; |
| 150 | } |
| 151 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 152 | div.listingblock { |
| 153 | margin-right: 0%; |
| 154 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 155 | div.listingblock > div.content { |
| 156 | border: 1px solid silver; |
| 157 | background: #f4f4f4; |
| 158 | padding: 0.5em; |
| 159 | } |
| 160 | |
| 161 | div.quoteblock > div.content { |
| 162 | padding-left: 2.0em; |
| 163 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 164 | |
| 165 | div.attribution { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 166 | text-align: right; |
| 167 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 168 | div.verseblock + div.attribution { |
| 169 | text-align: left; |
| 170 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 171 | |
| 172 | div.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 | } |
| 180 | div.admonitionblock td.content { |
| 181 | padding-left: 0.5em; |
| 182 | border-left: 2px solid silver; |
| 183 | } |
| 184 | |
| 185 | div.exampleblock > div.content { |
| 186 | border-left: 2px solid silver; |
| 187 | padding: 0.5em; |
| 188 | } |
| 189 | |
| 190 | div.verseblock div.content { |
| 191 | white-space: pre; |
| 192 | } |
| 193 | |
| 194 | div.imageblock div.content { padding-left: 0; } |
| 195 | div.imageblock img { border: 1px solid silver; } |
| 196 | span.image img { border-style: none; } |
| 197 | |
| 198 | dl { |
| 199 | margin-top: 0.8em; |
| 200 | margin-bottom: 0.8em; |
| 201 | } |
| 202 | dt { |
| 203 | margin-top: 0.5em; |
| 204 | margin-bottom: 0; |
| 205 | font-style: italic; |
| 206 | } |
| 207 | dd > *:first-child { |
| 208 | margin-top: 0; |
| 209 | } |
| 210 | |
| 211 | ul, ol { |
| 212 | list-style-position: outside; |
| 213 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 214 | div.olist2 ol { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 215 | list-style-type: lower-alpha; |
| 216 | } |
| 217 | |
| 218 | div.tableblock > table { |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 219 | border: 3px solid #527bbd; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 220 | } |
| 221 | thead { |
| 222 | font-family: sans-serif; |
| 223 | font-weight: bold; |
| 224 | } |
| 225 | tfoot { |
| 226 | font-weight: bold; |
| 227 | } |
| 228 | |
| 229 | div.hlist { |
| 230 | margin-top: 0.8em; |
| 231 | margin-bottom: 0.8em; |
| 232 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 233 | div.hlist td { |
| 234 | padding-bottom: 5px; |
| 235 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 236 | td.hlist1 { |
| 237 | vertical-align: top; |
| 238 | font-style: italic; |
| 239 | padding-right: 0.8em; |
| 240 | } |
| 241 | td.hlist2 { |
| 242 | vertical-align: top; |
| 243 | } |
| 244 | |
| 245 | @media print { |
| 246 | div#footer-badges { display: none; } |
| 247 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 248 | |
| 249 | div#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 | |
| 258 | div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 259 | margin-top: 0; |
| 260 | margin-bottom: 0; |
| 261 | } |
| 262 | div.toclevel2 { |
| 263 | margin-left: 2em; |
| 264 | font-size: 0.9em; |
| 265 | } |
| 266 | div.toclevel3 { |
| 267 | margin-left: 4em; |
| 268 | font-size: 0.9em; |
| 269 | } |
| 270 | div.toclevel4 { |
| 271 | margin-left: 6em; |
| 272 | font-size: 0.9em; |
| 273 | } |
| 274 | include1::./stylesheets/xhtml11-manpage.css[] |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 275 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 276 | |
| 277 | div.sidebar-content { |
| 278 | background: #ffffee; |
| 279 | border: 1px solid silver; |
| 280 | padding: 0.5em; |
| 281 | } |
| 282 | div.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 | |
| 289 | div.listingblock div.content { |
| 290 | border: 1px solid silver; |
| 291 | background: #f4f4f4; |
| 292 | padding: 0.5em; |
| 293 | } |
| 294 | |
| 295 | div.quoteblock-content { |
| 296 | padding-left: 2.0em; |
| 297 | } |
| 298 | |
| 299 | div.exampleblock-content { |
| 300 | border-left: 2px solid silver; |
| 301 | padding-left: 0.5em; |
| 302 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 303 | |
| 304 | /* IE6 sets dynamically generated links as visited. */ |
| 305 | div#toc a:visited { color: blue; } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 306 | </style> |
| 307 | <title>git-checkout(1)</title> |
| 308 | </head> |
| 309 | <body> |
| 310 | <div id="header"> |
| 311 | <h1> |
| 312 | git-checkout(1) Manual Page |
| 313 | </h1> |
| 314 | <h2>NAME</h2> |
| 315 | <div class="sectionbody"> |
| 316 | <p>git-checkout - |
| Junio C Hamano | a14a403 | 2008-03-25 09:11:02 | [diff] [blame] | 317 | Checkout a branch or paths to the working tree |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 318 | </p> |
| 319 | </div> |
| 320 | </div> |
| 321 | <h2>SYNOPSIS</h2> |
| 322 | <div class="sectionbody"> |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 323 | <div class="verseblock"> |
| Junio C Hamano | 5cf43ca | 2008-08-20 09:14:14 | [diff] [blame] | 324 | <div class="content"><em>git checkout</em> [-q] [-f] [--track | --no-track] [-b <new_branch> [-l]] [-m] [<branch>] |
| Junio C Hamano | 3db8b41 | 2008-07-26 06:45:59 | [diff] [blame] | 325 | <em>git checkout</em> [<tree-ish>] [--] <paths>…</div></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 326 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 327 | <h2 id="_description">DESCRIPTION</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 328 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 329 | <div class="para"><p>When <paths> are not given, this command switches branches by |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 330 | updating the index and working tree to reflect the specified |
| 331 | branch, <branch>, and updating HEAD to be <branch> or, if |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 332 | specified, <new_branch>. Using -b will cause <new_branch> to |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 333 | be created; in this case you can use the --track or --no-track |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 334 | options, which will be passed to <tt>git branch</tt>.</p></div> |
| Junio C Hamano | 5cf43ca | 2008-08-20 09:14:14 | [diff] [blame] | 335 | <div class="para"><p>As a convenience, --track will default to create a branch whose |
| 336 | name is constructed from the specified branch name by stripping |
| 337 | the first namespace level.</p></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 338 | <div class="para"><p>When <paths> are given, this command does <strong>not</strong> switch |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 339 | branches. It updates the named paths in the working tree from |
| Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 340 | the index file (i.e. it runs <tt>git checkout-index -f -u</tt>), or |
| Junio C Hamano | 0e3cb53 | 2007-04-17 08:28:11 | [diff] [blame] | 341 | from a named commit. In |
| 342 | this case, the <tt>-f</tt> and <tt>-b</tt> options are meaningless and giving |
| Junio C Hamano | 8f62db9 | 2007-02-01 00:22:22 | [diff] [blame] | 343 | either of them results in an error. <tree-ish> argument can be |
| 344 | used to specify a specific tree-ish (i.e. commit, tag or tree) |
| 345 | to update the index for the given paths before updating the |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 346 | working tree.</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 347 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 348 | <h2 id="_options">OPTIONS</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 349 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 350 | <div class="vlist"><dl> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 351 | <dt> |
| Junio C Hamano | 39381a7 | 2007-02-02 07:35:15 | [diff] [blame] | 352 | -q |
| 353 | </dt> |
| 354 | <dd> |
| 355 | <p> |
| Junio C Hamano | cae8627 | 2007-08-21 02:20:49 | [diff] [blame] | 356 | Quiet, suppress feedback messages. |
| Junio C Hamano | 39381a7 | 2007-02-02 07:35:15 | [diff] [blame] | 357 | </p> |
| 358 | </dd> |
| 359 | <dt> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 360 | -f |
| 361 | </dt> |
| 362 | <dd> |
| 363 | <p> |
| Junio C Hamano | 0e3cb53 | 2007-04-17 08:28:11 | [diff] [blame] | 364 | Proceed even if the index or the working tree differs |
| 365 | from HEAD. This is used to throw away local changes. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 366 | </p> |
| 367 | </dd> |
| 368 | <dt> |
| 369 | -b |
| 370 | </dt> |
| 371 | <dd> |
| 372 | <p> |
| Junio C Hamano | b2f5edd | 2006-05-21 10:50:09 | [diff] [blame] | 373 | Create a new branch named <new_branch> and start it at |
| 374 | <branch>. The new branch name must pass all checks defined |
| 375 | by <a href="git-check-ref-format.html">git-check-ref-format(1)</a>. Some of these checks |
| 376 | may restrict the characters allowed in a branch name. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 377 | </p> |
| 378 | </dd> |
| 379 | <dt> |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 380 | -t |
| 381 | </dt> |
| 382 | <dt> |
| 383 | --track |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 384 | </dt> |
| 385 | <dd> |
| 386 | <p> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 387 | When creating a new branch, set up configuration so that <em>git-pull</em> |
| Junio C Hamano | 24bc09a | 2008-02-28 00:27:44 | [diff] [blame] | 388 | will automatically retrieve data from the start point, which must be |
| 389 | a branch. Use this if you always pull from the same upstream branch |
| 390 | into the new branch, and if you don't want to use "git pull |
| 391 | <repository> <refspec>" explicitly. This behavior is the default |
| 392 | when the start point is a remote branch. Set the |
| 393 | branch.autosetupmerge configuration variable to <tt>false</tt> if you want |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 394 | <em>git-checkout</em> and <em>git-branch</em> to always behave as if <em>--no-track</em> were |
| Junio C Hamano | 24bc09a | 2008-02-28 00:27:44 | [diff] [blame] | 395 | given. Set it to <tt>always</tt> if you want this behavior when the |
| 396 | start-point is either a local or remote branch. |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 397 | </p> |
| Junio C Hamano | 043628e | 2008-08-24 03:34:11 | [diff] [blame] | 398 | <div class="para"><p>If no <em>-b</em> option was given, the name of the new branch will be |
| 399 | derived from the remote branch, by attempting to guess the name |
| 400 | of the branch on remote system. If "remotes/" or "refs/remotes/" |
| 401 | are prefixed, it is stripped away, and then the part up to the |
| 402 | next slash (which would be the nickname of the remote) is removed. |
| 403 | This would tell us to use "hack" as the local branch when branching |
| 404 | off of "origin/hack" (or "remotes/origin/hack", or even |
| 405 | "refs/remotes/origin/hack"). If the given name has no slash, or the above |
| 406 | guessing results in an empty name, the guessing is aborted. You can |
| 407 | exlicitly give a name with <em>-b</em> in such a case.</p></div> |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 408 | </dd> |
| 409 | <dt> |
| 410 | --no-track |
| 411 | </dt> |
| 412 | <dd> |
| 413 | <p> |
| Junio C Hamano | 24bc09a | 2008-02-28 00:27:44 | [diff] [blame] | 414 | Ignore the branch.autosetupmerge configuration variable. |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 415 | </p> |
| 416 | </dd> |
| 417 | <dt> |
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 418 | -l |
| 419 | </dt> |
| 420 | <dd> |
| 421 | <p> |
| Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 422 | Create the new branch's reflog. This activates recording of |
| 423 | all changes made to the branch ref, enabling use of date |
| 424 | based sha1 expressions such as "<branchname>@{yesterday}". |
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 425 | </p> |
| 426 | </dd> |
| 427 | <dt> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 428 | -m |
| 429 | </dt> |
| 430 | <dd> |
| 431 | <p> |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 432 | If you have local modifications to one or more files that |
| 433 | are different between the current branch and the branch to |
| 434 | which you are switching, the command refuses to switch |
| 435 | branches in order to preserve your modifications in context. |
| 436 | However, with this option, a three-way merge between the current |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 437 | branch, your working tree contents, and the new branch |
| 438 | is done, and you will be on the new branch. |
| 439 | </p> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 440 | <div class="para"><p>When a merge conflict happens, the index entries for conflicting |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 441 | paths are left unmerged, and you need to resolve the conflicts |
| Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 442 | and mark the resolved paths with <tt>git add</tt> (or <tt>git rm</tt> if the merge |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 443 | should result in deletion of the path).</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 444 | </dd> |
| 445 | <dt> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 446 | <new_branch> |
| 447 | </dt> |
| 448 | <dd> |
| 449 | <p> |
| 450 | Name for the new branch. |
| 451 | </p> |
| 452 | </dd> |
| 453 | <dt> |
| 454 | <branch> |
| 455 | </dt> |
| 456 | <dd> |
| 457 | <p> |
| 458 | Branch to checkout; may be any object ID that resolves to a |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 459 | commit. Defaults to HEAD. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 460 | </p> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 461 | <div class="para"><p>When this parameter names a non-branch (but still a valid commit object), |
| 462 | your HEAD becomes <em>detached</em>.</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 463 | </dd> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 464 | </dl></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 465 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 466 | <h2 id="_detached_head">Detached HEAD</h2> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 467 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 468 | <div class="para"><p>It is sometimes useful to be able to <em>checkout</em> a commit that is |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 469 | not at the tip of one of your branches. The most obvious |
| 470 | example is to check out the commit at a tagged official release |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 471 | point, like this:</p></div> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 472 | <div class="listingblock"> |
| 473 | <div class="content"> |
| 474 | <pre><tt>$ git checkout v2.6.18</tt></pre> |
| 475 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 476 | <div class="para"><p>Earlier versions of git did not allow this and asked you to |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 477 | create a temporary branch using <tt>-b</tt> option, but starting from |
| 478 | version 1.5.0, the above command <em>detaches</em> your HEAD from the |
| 479 | current branch and directly point at the commit named by the tag |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 480 | (<tt>v2.6.18</tt> in the above example).</p></div> |
| 481 | <div class="para"><p>You can use usual git commands while in this state. You can use |
| Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 482 | <tt>git reset --hard $othercommit</tt> to further move around, for |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 483 | example. You can make changes and create a new commit on top of |
| 484 | a detached HEAD. You can even create a merge by using <tt>git |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 485 | merge $othercommit</tt>.</p></div> |
| 486 | <div class="para"><p>The state you are in while your HEAD is detached is not recorded |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 487 | by any branch (which is natural --- you are not on any branch). |
| 488 | What this means is that you can discard your temporary commits |
| 489 | and merges by switching back to an existing branch (e.g. <tt>git |
| 490 | checkout master</tt>), and a later <tt>git prune</tt> or <tt>git gc</tt> would |
| Junio C Hamano | 9d52e57 | 2007-02-13 23:48:20 | [diff] [blame] | 491 | garbage-collect them. If you did this by mistake, you can ask |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 492 | the reflog for HEAD where you were, e.g.</p></div> |
| Junio C Hamano | 9d52e57 | 2007-02-13 23:48:20 | [diff] [blame] | 493 | <div class="listingblock"> |
| 494 | <div class="content"> |
| 495 | <pre><tt>$ git log -g -2 HEAD</tt></pre> |
| 496 | </div></div> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 497 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 498 | <h2 id="_examples">EXAMPLES</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 499 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 500 | <div class="olist"><ol> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 501 | <li> |
| 502 | <p> |
| 503 | The following sequence checks out the <tt>master</tt> branch, reverts |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 504 | the <tt>Makefile</tt> to two revisions back, deletes hello.c by |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 505 | mistake, and gets it back from the index. |
| 506 | </p> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 507 | <div class="listingblock"> |
| 508 | <div class="content"> |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 509 | <pre><tt>$ git checkout master <b>(1)</b> |
| 510 | $ git checkout master~2 Makefile <b>(2)</b> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 511 | $ rm -f hello.c |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 512 | $ git checkout hello.c <b>(3)</b></tt></pre> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 513 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 514 | <div class="colist"><ol> |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 515 | <li> |
| 516 | <p> |
| 517 | switch branch |
| 518 | </p> |
| 519 | </li> |
| 520 | <li> |
| 521 | <p> |
| 522 | take out a file out of other commit |
| 523 | </p> |
| 524 | </li> |
| 525 | <li> |
| 526 | <p> |
| 527 | restore hello.c from HEAD of current branch |
| 528 | </p> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 529 | <div class="para"><p>If you have an unfortunate branch that is named <tt>hello.c</tt>, this |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 530 | step would be confused as an instruction to switch to that branch. |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 531 | You should instead write:</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 532 | <div class="listingblock"> |
| 533 | <div class="content"> |
| 534 | <pre><tt>$ git checkout -- hello.c</tt></pre> |
| 535 | </div></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 536 | </li> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 537 | </ol></div> |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 538 | </li> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 539 | <li> |
| 540 | <p> |
| 541 | After working in a wrong branch, switching to the correct |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 542 | branch would be done using: |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 543 | </p> |
| 544 | <div class="listingblock"> |
| 545 | <div class="content"> |
| 546 | <pre><tt>$ git checkout mytopic</tt></pre> |
| 547 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 548 | <div class="para"><p>However, your "wrong" branch and correct "mytopic" branch may |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 549 | differ in files that you have locally modified, in which case, |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 550 | the above checkout would fail like this:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 551 | <div class="listingblock"> |
| 552 | <div class="content"> |
| 553 | <pre><tt>$ git checkout mytopic |
| 554 | fatal: Entry 'frotz' not uptodate. Cannot merge.</tt></pre> |
| 555 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 556 | <div class="para"><p>You can give the <tt>-m</tt> flag to the command, which would try a |
| 557 | three-way merge:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 558 | <div class="listingblock"> |
| 559 | <div class="content"> |
| 560 | <pre><tt>$ git checkout -m mytopic |
| 561 | Auto-merging frotz</tt></pre> |
| 562 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 563 | <div class="para"><p>After this three-way merge, the local modifications are <em>not</em> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 564 | registered in your index file, so <tt>git diff</tt> would show you what |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 565 | changes you made since the tip of the new branch.</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 566 | </li> |
| 567 | <li> |
| 568 | <p> |
| 569 | When a merge conflict happens during switching branches with |
| 570 | the <tt>-m</tt> option, you would see something like this: |
| 571 | </p> |
| 572 | <div class="listingblock"> |
| 573 | <div class="content"> |
| 574 | <pre><tt>$ git checkout -m mytopic |
| 575 | Auto-merging frotz |
| 576 | merge: warning: conflicts during merge |
| 577 | ERROR: Merge conflict in frotz |
| 578 | fatal: merge program failed</tt></pre> |
| 579 | </div></div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 580 | <div class="para"><p>At this point, <tt>git diff</tt> shows the changes cleanly merged as in |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 581 | the previous example, as well as the changes in the conflicted |
| 582 | files. Edit and resolve the conflict and mark it resolved with |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 583 | <tt>git add</tt> as usual:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 584 | <div class="listingblock"> |
| 585 | <div class="content"> |
| 586 | <pre><tt>$ edit frotz |
| Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 587 | $ git add frotz</tt></pre> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 588 | </div></div> |
| 589 | </li> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 590 | </ol></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 591 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 592 | <h2 id="_author">Author</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 593 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 594 | <div class="para"><p>Written by Linus Torvalds <torvalds@osdl.org></p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 595 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 596 | <h2 id="_documentation">Documentation</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 597 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 598 | <div class="para"><p>Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 599 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 600 | <h2 id="_git">GIT</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 601 | <div class="sectionbody"> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 602 | <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 603 | </div> |
| 604 | <div id="footer"> |
| 605 | <div id="footer-text"> |
| Junio C Hamano | 043628e | 2008-08-24 03:34:11 | [diff] [blame] | 606 | Last updated 2008-08-24 03:33:55 UTC |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 607 | </div> |
| 608 | </div> |
| 609 | </body> |
| 610 | </html> |