| 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 | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 8.4.5" /> |
| 7 | <title>git-checkout(1)</title> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 8 | <style type="text/css"> |
| 9 | /* Debug borders */ |
| 10 | p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { |
| 11 | /* |
| 12 | border: 1px solid red; |
| 13 | */ |
| 14 | } |
| 15 | |
| 16 | body { |
| 17 | margin: 1em 5% 1em 5%; |
| 18 | } |
| 19 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 20 | a { |
| 21 | color: blue; |
| 22 | text-decoration: underline; |
| 23 | } |
| 24 | a:visited { |
| 25 | color: fuchsia; |
| 26 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 27 | |
| 28 | em { |
| 29 | font-style: italic; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 30 | color: navy; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | strong { |
| 34 | font-weight: bold; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 35 | color: #083194; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | tt { |
| 39 | color: navy; |
| 40 | } |
| 41 | |
| 42 | h1, h2, h3, h4, h5, h6 { |
| 43 | color: #527bbd; |
| 44 | font-family: sans-serif; |
| 45 | margin-top: 1.2em; |
| 46 | margin-bottom: 0.5em; |
| 47 | line-height: 1.3; |
| 48 | } |
| 49 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 50 | h1, h2, h3 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 51 | border-bottom: 2px solid silver; |
| 52 | } |
| 53 | h2 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 54 | padding-top: 0.5em; |
| 55 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 56 | h3 { |
| 57 | float: left; |
| 58 | } |
| 59 | h3 + * { |
| 60 | clear: left; |
| 61 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 62 | |
| 63 | div.sectionbody { |
| 64 | font-family: serif; |
| 65 | margin-left: 0; |
| 66 | } |
| 67 | |
| 68 | hr { |
| 69 | border: 1px solid silver; |
| 70 | } |
| 71 | |
| 72 | p { |
| 73 | margin-top: 0.5em; |
| 74 | margin-bottom: 0.5em; |
| 75 | } |
| 76 | |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 77 | ul, ol, li > p { |
| 78 | margin-top: 0; |
| 79 | } |
| 80 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 81 | pre { |
| 82 | padding: 0; |
| 83 | margin: 0; |
| 84 | } |
| 85 | |
| 86 | span#author { |
| 87 | color: #527bbd; |
| 88 | font-family: sans-serif; |
| 89 | font-weight: bold; |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 90 | font-size: 1.1em; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 91 | } |
| 92 | span#email { |
| 93 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 94 | span#revnumber, span#revdate, span#revremark { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 95 | font-family: sans-serif; |
| 96 | } |
| 97 | |
| 98 | div#footer { |
| 99 | font-family: sans-serif; |
| 100 | font-size: small; |
| 101 | border-top: 2px solid silver; |
| 102 | padding-top: 0.5em; |
| 103 | margin-top: 4.0em; |
| 104 | } |
| 105 | div#footer-text { |
| 106 | float: left; |
| 107 | padding-bottom: 0.5em; |
| 108 | } |
| 109 | div#footer-badges { |
| 110 | float: right; |
| 111 | padding-bottom: 0.5em; |
| 112 | } |
| 113 | |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 114 | div#preamble { |
| 115 | margin-top: 1.5em; |
| 116 | margin-bottom: 1.5em; |
| 117 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 118 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 119 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 120 | div.admonitionblock { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 121 | margin-top: 1.5em; |
| 122 | margin-bottom: 1.5em; |
| 123 | } |
| 124 | div.admonitionblock { |
| 125 | margin-top: 2.5em; |
| 126 | margin-bottom: 2.5em; |
| 127 | } |
| 128 | |
| 129 | div.content { /* Block element content. */ |
| 130 | padding: 0; |
| 131 | } |
| 132 | |
| 133 | /* Block element titles. */ |
| 134 | div.title, caption.title { |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 135 | color: #527bbd; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 136 | font-family: sans-serif; |
| 137 | font-weight: bold; |
| 138 | text-align: left; |
| 139 | margin-top: 1.0em; |
| 140 | margin-bottom: 0.5em; |
| 141 | } |
| 142 | div.title + * { |
| 143 | margin-top: 0; |
| 144 | } |
| 145 | |
| 146 | td div.title:first-child { |
| 147 | margin-top: 0.0em; |
| 148 | } |
| 149 | div.content div.title:first-child { |
| 150 | margin-top: 0.0em; |
| 151 | } |
| 152 | div.content + div.title { |
| 153 | margin-top: 0.0em; |
| 154 | } |
| 155 | |
| 156 | div.sidebarblock > div.content { |
| 157 | background: #ffffee; |
| 158 | border: 1px solid silver; |
| 159 | padding: 0.5em; |
| 160 | } |
| 161 | |
| 162 | div.listingblock > div.content { |
| 163 | border: 1px solid silver; |
| 164 | background: #f4f4f4; |
| 165 | padding: 0.5em; |
| 166 | } |
| 167 | |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 168 | div.quoteblock { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 169 | padding-left: 2.0em; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 170 | margin-right: 10%; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 171 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 172 | div.quoteblock > div.attribution { |
| 173 | padding-top: 0.5em; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 174 | text-align: right; |
| 175 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 176 | |
| 177 | div.verseblock { |
| 178 | padding-left: 2.0em; |
| 179 | margin-right: 10%; |
| 180 | } |
| 181 | div.verseblock > div.content { |
| 182 | white-space: pre; |
| 183 | } |
| 184 | div.verseblock > div.attribution { |
| 185 | padding-top: 0.75em; |
| 186 | text-align: left; |
| 187 | } |
| 188 | /* DEPRECATED: Pre version 8.2.7 verse style literal block. */ |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 189 | div.verseblock + div.attribution { |
| 190 | text-align: left; |
| 191 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 192 | |
| 193 | div.admonitionblock .icon { |
| 194 | vertical-align: top; |
| 195 | font-size: 1.1em; |
| 196 | font-weight: bold; |
| 197 | text-decoration: underline; |
| 198 | color: #527bbd; |
| 199 | padding-right: 0.5em; |
| 200 | } |
| 201 | div.admonitionblock td.content { |
| 202 | padding-left: 0.5em; |
| 203 | border-left: 2px solid silver; |
| 204 | } |
| 205 | |
| 206 | div.exampleblock > div.content { |
| 207 | border-left: 2px solid silver; |
| 208 | padding: 0.5em; |
| 209 | } |
| 210 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 211 | div.imageblock div.content { padding-left: 0; } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 212 | span.image img { border-style: none; } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 213 | a.image:visited { color: white; } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 214 | |
| 215 | dl { |
| 216 | margin-top: 0.8em; |
| 217 | margin-bottom: 0.8em; |
| 218 | } |
| 219 | dt { |
| 220 | margin-top: 0.5em; |
| 221 | margin-bottom: 0; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 222 | font-style: normal; |
| 223 | color: navy; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 224 | } |
| 225 | dd > *:first-child { |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 226 | margin-top: 0.1em; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | ul, ol { |
| 230 | list-style-position: outside; |
| 231 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 232 | ol.arabic { |
| 233 | list-style-type: decimal; |
| 234 | } |
| 235 | ol.loweralpha { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 236 | list-style-type: lower-alpha; |
| 237 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 238 | ol.upperalpha { |
| 239 | list-style-type: upper-alpha; |
| 240 | } |
| 241 | ol.lowerroman { |
| 242 | list-style-type: lower-roman; |
| 243 | } |
| 244 | ol.upperroman { |
| 245 | list-style-type: upper-roman; |
| 246 | } |
| 247 | |
| 248 | div.compact ul, div.compact ol, |
| 249 | div.compact p, div.compact p, |
| 250 | div.compact div, div.compact div { |
| 251 | margin-top: 0.1em; |
| 252 | margin-bottom: 0.1em; |
| 253 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 254 | |
| 255 | div.tableblock > table { |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 256 | border: 3px solid #527bbd; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 257 | } |
| 258 | thead { |
| 259 | font-family: sans-serif; |
| 260 | font-weight: bold; |
| 261 | } |
| 262 | tfoot { |
| 263 | font-weight: bold; |
| 264 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 265 | td > div.verse { |
| 266 | white-space: pre; |
| 267 | } |
| 268 | p.table { |
| 269 | margin-top: 0; |
| 270 | } |
| 271 | /* Because the table frame attribute is overriden by CSS in most browsers. */ |
| 272 | div.tableblock > table[frame="void"] { |
| 273 | border-style: none; |
| 274 | } |
| 275 | div.tableblock > table[frame="hsides"] { |
| 276 | border-left-style: none; |
| 277 | border-right-style: none; |
| 278 | } |
| 279 | div.tableblock > table[frame="vsides"] { |
| 280 | border-top-style: none; |
| 281 | border-bottom-style: none; |
| 282 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 283 | |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 284 | |
| 285 | div.hdlist { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 286 | margin-top: 0.8em; |
| 287 | margin-bottom: 0.8em; |
| 288 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 289 | div.hdlist tr { |
| 290 | padding-bottom: 15px; |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 291 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 292 | dt.hdlist1.strong, td.hdlist1.strong { |
| 293 | font-weight: bold; |
| 294 | } |
| 295 | td.hdlist1 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 296 | vertical-align: top; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 297 | font-style: normal; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 298 | padding-right: 0.8em; |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 299 | color: navy; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 300 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 301 | td.hdlist2 { |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 302 | vertical-align: top; |
| 303 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 304 | div.hdlist.compact tr { |
| 305 | margin: 0; |
| 306 | padding-bottom: 0; |
| 307 | } |
| 308 | |
| 309 | .comment { |
| 310 | background: yellow; |
| 311 | } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 312 | |
| 313 | @media print { |
| 314 | div#footer-badges { display: none; } |
| 315 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 316 | |
| 317 | div#toctitle { |
| 318 | color: #527bbd; |
| 319 | font-family: sans-serif; |
| 320 | font-size: 1.1em; |
| 321 | font-weight: bold; |
| 322 | margin-top: 1.0em; |
| 323 | margin-bottom: 0.1em; |
| 324 | } |
| 325 | |
| 326 | div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 327 | margin-top: 0; |
| 328 | margin-bottom: 0; |
| 329 | } |
| 330 | div.toclevel2 { |
| 331 | margin-left: 2em; |
| 332 | font-size: 0.9em; |
| 333 | } |
| 334 | div.toclevel3 { |
| 335 | margin-left: 4em; |
| 336 | font-size: 0.9em; |
| 337 | } |
| 338 | div.toclevel4 { |
| 339 | margin-left: 6em; |
| 340 | font-size: 0.9em; |
| 341 | } |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 342 | /* Overrides for manpage documents */ |
| 343 | h1 { |
| 344 | padding-top: 0.5em; |
| 345 | padding-bottom: 0.5em; |
| 346 | border-top: 2px solid silver; |
| 347 | border-bottom: 2px solid silver; |
| 348 | } |
| 349 | h2 { |
| 350 | border-style: none; |
| 351 | } |
| 352 | div.sectionbody { |
| 353 | margin-left: 5%; |
| 354 | } |
| 355 | |
| 356 | @media print { |
| 357 | div#toc { display: none; } |
| 358 | } |
| 359 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 360 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 361 | |
| 362 | div.sidebar-content { |
| 363 | background: #ffffee; |
| 364 | border: 1px solid silver; |
| 365 | padding: 0.5em; |
| 366 | } |
| 367 | div.sidebar-title, div.image-title { |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 368 | color: #527bbd; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 369 | font-family: sans-serif; |
| 370 | font-weight: bold; |
| 371 | margin-top: 0.0em; |
| 372 | margin-bottom: 0.5em; |
| 373 | } |
| 374 | |
| 375 | div.listingblock div.content { |
| 376 | border: 1px solid silver; |
| 377 | background: #f4f4f4; |
| 378 | padding: 0.5em; |
| 379 | } |
| 380 | |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 381 | div.quoteblock-attribution { |
| 382 | padding-top: 0.5em; |
| 383 | text-align: right; |
| 384 | } |
| 385 | |
| 386 | div.verseblock-content { |
| 387 | white-space: pre; |
| 388 | } |
| 389 | div.verseblock-attribution { |
| 390 | padding-top: 0.75em; |
| 391 | text-align: left; |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | div.exampleblock-content { |
| 395 | border-left: 2px solid silver; |
| 396 | padding-left: 0.5em; |
| 397 | } |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 398 | |
| 399 | /* IE6 sets dynamically generated links as visited. */ |
| 400 | div#toc a:visited { color: blue; } |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 401 | </style> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 402 | </head> |
| 403 | <body> |
| 404 | <div id="header"> |
| 405 | <h1> |
| 406 | git-checkout(1) Manual Page |
| 407 | </h1> |
| 408 | <h2>NAME</h2> |
| 409 | <div class="sectionbody"> |
| 410 | <p>git-checkout - |
| Junio C Hamano | a14a403 | 2008-03-25 09:11:02 | [diff] [blame] | 411 | Checkout a branch or paths to the working tree |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 412 | </p> |
| 413 | </div> |
| 414 | </div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 415 | <h2 id="_synopsis">SYNOPSIS</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 416 | <div class="sectionbody"> |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 417 | <div class="verseblock"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 418 | <div class="verseblock-content"><em>git checkout</em> [-q] [-f] [-m] [<branch>] |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 419 | <em>git checkout</em> [-q] [-f] [-m] [--detach] [<commit>] |
| Junio C Hamano | 619596a | 2010-08-18 22:15:35 | [diff] [blame] | 420 | <em>git checkout</em> [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>] |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 421 | <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>… |
| Junio C Hamano | 9eb5835 | 2011-05-11 20:09:24 | [diff] [blame^] | 422 | <em>git checkout</em> [-p|--patch] [<tree-ish>] [--] [<paths>…]</div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 423 | <div class="verseblock-attribution"> |
| 424 | </div></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 425 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 426 | <h2 id="_description">DESCRIPTION</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 427 | <div class="sectionbody"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 428 | <div class="paragraph"><p>Updates files in the working tree to match the version in the index |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 429 | or the specified tree. If no paths are given, <em>git checkout</em> will |
| 430 | also update <tt>HEAD</tt> to set the specified branch as the current |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 431 | branch.</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 432 | <div class="dlist"><dl> |
| 433 | <dt class="hdlist1"> |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 434 | <em>git checkout</em> [<branch>] |
| 435 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 436 | <dt class="hdlist1"> |
| Junio C Hamano | 619596a | 2010-08-18 22:15:35 | [diff] [blame] | 437 | <em>git checkout</em> -b|-B <new_branch> [<start point>] |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 438 | </dt> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 439 | <dt class="hdlist1"> |
| 440 | <em>git checkout</em> [--detach] [<commit>] |
| 441 | </dt> |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 442 | <dd> |
| 443 | <p> |
| 444 | This form switches branches by updating the index, working |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 445 | tree, and HEAD to reflect the specified branch or commit. |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 446 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 447 | <div class="paragraph"><p>If <tt>-b</tt> is given, a new branch is created as if <a href="git-branch.html">git-branch(1)</a> |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 448 | were called and then checked out; in this case you can |
| 449 | use the <tt>--track</tt> or <tt>--no-track</tt> options, which will be passed to |
| 450 | <em>git branch</em>. As a convenience, <tt>--track</tt> without <tt>-b</tt> implies branch |
| 451 | creation; see the description of <tt>--track</tt> below.</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 452 | <div class="paragraph"><p>If <tt>-B</tt> is given, <new_branch> is created if it doesn’t exist; otherwise, it |
| Junio C Hamano | 619596a | 2010-08-18 22:15:35 | [diff] [blame] | 453 | is reset. This is the transactional equivalent of</p></div> |
| 454 | <div class="listingblock"> |
| 455 | <div class="content"> |
| 456 | <pre><tt>$ git branch -f <branch> [<start point>] |
| 457 | $ git checkout <branch></tt></pre> |
| 458 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 459 | <div class="paragraph"><p>that is to say, the branch is not reset/created unless "git checkout" is |
| Junio C Hamano | 619596a | 2010-08-18 22:15:35 | [diff] [blame] | 460 | successful.</p></div> |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 461 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 462 | <dt class="hdlist1"> |
| Junio C Hamano | 9eb5835 | 2011-05-11 20:09:24 | [diff] [blame^] | 463 | <em>git checkout</em> [-p|--patch] [<tree-ish>] [--] <pathspec>… |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 464 | </dt> |
| 465 | <dd> |
| 466 | <p> |
| Junio C Hamano | 442206c | 2010-09-28 05:51:23 | [diff] [blame] | 467 | When <paths> or <tt>--patch</tt> are given, <em>git checkout</em> does <strong>not</strong> |
| 468 | switch branches. It updates the named paths in the working tree |
| 469 | from the index file or from a named <tree-ish> (most often a |
| 470 | commit). In this case, the <tt>-b</tt> and <tt>--track</tt> options are |
| 471 | meaningless and giving either of them results in an error. The |
| 472 | <tree-ish> argument can be used to specify a specific tree-ish |
| 473 | (i.e. commit, tag or tree) to update the index for the given |
| 474 | paths before updating the working tree. |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 475 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 476 | <div class="paragraph"><p>The index may contain unmerged entries because of a previous failed merge. |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 477 | By default, if you try to check out such an entry from the index, the |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 478 | checkout operation will fail and nothing will be checked out. |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 479 | Using <tt>-f</tt> will ignore these unmerged entries. The contents from a |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 480 | specific side of the merge can be checked out of the index by |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 481 | using <tt>--ours</tt> or <tt>--theirs</tt>. With <tt>-m</tt>, changes made to the working tree |
| 482 | file can be discarded to re-create the original conflicted merge result.</p></div> |
| 483 | </dd> |
| 484 | </dl></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 485 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 486 | <h2 id="_options">OPTIONS</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 487 | <div class="sectionbody"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 488 | <div class="dlist"><dl> |
| 489 | <dt class="hdlist1"> |
| Junio C Hamano | 39381a7 | 2007-02-02 07:35:15 | [diff] [blame] | 490 | -q |
| 491 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 492 | <dt class="hdlist1"> |
| Junio C Hamano | 68cfa3a | 2009-08-30 00:22:55 | [diff] [blame] | 493 | --quiet |
| 494 | </dt> |
| Junio C Hamano | 39381a7 | 2007-02-02 07:35:15 | [diff] [blame] | 495 | <dd> |
| 496 | <p> |
| Junio C Hamano | cae8627 | 2007-08-21 02:20:49 | [diff] [blame] | 497 | Quiet, suppress feedback messages. |
| Junio C Hamano | 39381a7 | 2007-02-02 07:35:15 | [diff] [blame] | 498 | </p> |
| 499 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 500 | <dt class="hdlist1"> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 501 | -f |
| 502 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 503 | <dt class="hdlist1"> |
| Junio C Hamano | 68cfa3a | 2009-08-30 00:22:55 | [diff] [blame] | 504 | --force |
| 505 | </dt> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 506 | <dd> |
| 507 | <p> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 508 | When switching branches, proceed even if the index or the |
| 509 | working tree differs from HEAD. This is used to throw away |
| 510 | local changes. |
| 511 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 512 | <div class="paragraph"><p>When checking out paths from the index, do not fail upon unmerged |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 513 | entries; instead, unmerged entries are ignored.</p></div> |
| 514 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 515 | <dt class="hdlist1"> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 516 | --ours |
| 517 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 518 | <dt class="hdlist1"> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 519 | --theirs |
| 520 | </dt> |
| 521 | <dd> |
| 522 | <p> |
| 523 | When checking out paths from the index, check out stage #2 |
| 524 | (<em>ours</em>) or #3 (<em>theirs</em>) for unmerged paths. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 525 | </p> |
| 526 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 527 | <dt class="hdlist1"> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 528 | -b |
| 529 | </dt> |
| 530 | <dd> |
| 531 | <p> |
| Junio C Hamano | b2f5edd | 2006-05-21 10:50:09 | [diff] [blame] | 532 | Create a new branch named <new_branch> and start it at |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 533 | <start_point>; see <a href="git-branch.html">git-branch(1)</a> for details. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 534 | </p> |
| 535 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 536 | <dt class="hdlist1"> |
| Junio C Hamano | 619596a | 2010-08-18 22:15:35 | [diff] [blame] | 537 | -B |
| 538 | </dt> |
| 539 | <dd> |
| 540 | <p> |
| 541 | Creates the branch <new_branch> and start it at <start_point>; |
| 542 | if it already exists, then reset it to <start_point>. This is |
| 543 | equivalent to running "git branch" with "-f"; see |
| 544 | <a href="git-branch.html">git-branch(1)</a> for details. |
| 545 | </p> |
| 546 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 547 | <dt class="hdlist1"> |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 548 | -t |
| 549 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 550 | <dt class="hdlist1"> |
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 551 | --track |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 552 | </dt> |
| 553 | <dd> |
| 554 | <p> |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 555 | When creating a new branch, set up "upstream" configuration. See |
| 556 | "--track" in <a href="git-branch.html">git-branch(1)</a> for details. |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 557 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 558 | <div class="paragraph"><p>If no <em>-b</em> option is given, the name of the new branch will be |
| 559 | derived from the remote-tracking branch. If "remotes/" or "refs/remotes/" |
| Junio C Hamano | 5705393 | 2009-03-11 08:48:32 | [diff] [blame] | 560 | is prefixed it is stripped away, and then the part up to the |
| Junio C Hamano | 043628e | 2008-08-24 03:34:11 | [diff] [blame] | 561 | next slash (which would be the nickname of the remote) is removed. |
| 562 | This would tell us to use "hack" as the local branch when branching |
| 563 | off of "origin/hack" (or "remotes/origin/hack", or even |
| 564 | "refs/remotes/origin/hack"). If the given name has no slash, or the above |
| 565 | guessing results in an empty name, the guessing is aborted. You can |
| Junio C Hamano | 7d06a8a | 2008-10-20 05:42:33 | [diff] [blame] | 566 | explicitly 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] | 567 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 568 | <dt class="hdlist1"> |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 569 | --no-track |
| 570 | </dt> |
| 571 | <dd> |
| 572 | <p> |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 573 | Do not set up "upstream" configuration, even if the |
| 574 | branch.autosetupmerge configuration variable is true. |
| Junio C Hamano | 103ad7f | 2007-03-14 11:19:26 | [diff] [blame] | 575 | </p> |
| 576 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 577 | <dt class="hdlist1"> |
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 578 | -l |
| 579 | </dt> |
| 580 | <dd> |
| 581 | <p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 582 | Create the new branch’s reflog; see <a href="git-branch.html">git-branch(1)</a> for |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 583 | details. |
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 584 | </p> |
| 585 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 586 | <dt class="hdlist1"> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 587 | --detach |
| 588 | </dt> |
| 589 | <dd> |
| 590 | <p> |
| 591 | Rather than checking out a branch to work on it, check out a |
| 592 | commit for inspection and discardable experiments. |
| 593 | This is the default behavior of "git checkout <commit>" when |
| 594 | <commit> is not a branch name. See the "DETACHED HEAD" section |
| 595 | below for details. |
| 596 | </p> |
| 597 | </dd> |
| 598 | <dt class="hdlist1"> |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 599 | --orphan |
| 600 | </dt> |
| 601 | <dd> |
| 602 | <p> |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 603 | Create a new <em>orphan</em> branch, named <new_branch>, started from |
| 604 | <start_point> and switch to it. The first commit made on this |
| 605 | new branch will have no parents and it will be the root of a new |
| 606 | history totally disconnected from all the other branches and |
| 607 | commits. |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 608 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 609 | <div class="paragraph"><p>The index and the working tree are adjusted as if you had previously run |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 610 | "git checkout <start_point>". This allows you to start a new history |
| 611 | that records a set of paths similar to <start_point> by easily running |
| 612 | "git commit -a" to make the root commit.</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 613 | <div class="paragraph"><p>This can be useful when you want to publish the tree from a commit |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 614 | without exposing its full history. You might want to do this to publish |
| 615 | an open source branch of a project whose current tree is "clean", but |
| 616 | whose full history contains proprietary or otherwise encumbered bits of |
| 617 | code.</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 618 | <div class="paragraph"><p>If you want to start a disconnected history that records a set of paths |
| Junio C Hamano | bb88cf4 | 2010-06-21 15:23:55 | [diff] [blame] | 619 | that is totally different from the one of <start_point>, then you should |
| 620 | clear the index and the working tree right after creating the orphan |
| 621 | branch by running "git rm -rf ." from the top level of the working tree. |
| 622 | Afterwards you will be ready to prepare your new files, repopulating the |
| 623 | working tree, by copying them from elsewhere, extracting a tarball, etc.</p></div> |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 624 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 625 | <dt class="hdlist1"> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 626 | -m |
| 627 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 628 | <dt class="hdlist1"> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 629 | --merge |
| 630 | </dt> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 631 | <dd> |
| 632 | <p> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 633 | When switching branches, |
| 634 | if you have local modifications to one or more files that |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 635 | are different between the current branch and the branch to |
| 636 | which you are switching, the command refuses to switch |
| 637 | branches in order to preserve your modifications in context. |
| 638 | However, with this option, a three-way merge between the current |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 639 | branch, your working tree contents, and the new branch |
| 640 | is done, and you will be on the new branch. |
| 641 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 642 | <div class="paragraph"><p>When a merge conflict happens, the index entries for conflicting |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 643 | paths are left unmerged, and you need to resolve the conflicts |
| Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 644 | 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] | 645 | should result in deletion of the path).</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 646 | <div class="paragraph"><p>When checking out paths from the index, this option lets you recreate |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 647 | the conflicted merge in the specified paths.</p></div> |
| 648 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 649 | <dt class="hdlist1"> |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 650 | --conflict=<style> |
| 651 | </dt> |
| 652 | <dd> |
| 653 | <p> |
| 654 | The same as --merge option above, but changes the way the |
| 655 | conflicting hunks are presented, overriding the |
| 656 | merge.conflictstyle configuration variable. Possible values are |
| 657 | "merge" (default) and "diff3" (in addition to what is shown by |
| 658 | "merge" style, shows the original contents). |
| 659 | </p> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 660 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 661 | <dt class="hdlist1"> |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 662 | -p |
| 663 | </dt> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 664 | <dt class="hdlist1"> |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 665 | --patch |
| 666 | </dt> |
| 667 | <dd> |
| 668 | <p> |
| 669 | Interactively select hunks in the difference between the |
| 670 | <tree-ish> (or the index, if unspecified) and the working |
| 671 | tree. The chosen hunks are then applied in reverse to the |
| 672 | working tree (and if a <tree-ish> was specified, the index). |
| 673 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 674 | <div class="paragraph"><p>This means that you can use <tt>git checkout -p</tt> to selectively discard |
| Junio C Hamano | 9eb5835 | 2011-05-11 20:09:24 | [diff] [blame^] | 675 | edits from your current working tree. See the “Interactive Mode” |
| 676 | section of <a href="git-add.html">git-add(1)</a> to learn how to operate the <tt>--patch</tt> mode.</p></div> |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 677 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 678 | <dt class="hdlist1"> |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 679 | <branch> |
| 680 | </dt> |
| 681 | <dd> |
| 682 | <p> |
| 683 | Branch to checkout; if it refers to a branch (i.e., a name that, |
| 684 | when prepended with "refs/heads/", is a valid ref), then that |
| 685 | branch is checked out. Otherwise, if it refers to a valid |
| 686 | commit, your HEAD becomes "detached" and you are no longer on |
| 687 | any branch (see below for details). |
| 688 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 689 | <div class="paragraph"><p>As a special case, the <tt>"@{-N}"</tt> syntax for the N-th last branch |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 690 | checks out the branch (instead of detaching). You may also specify |
| 691 | <tt>-</tt> which is synonymous with <tt>"@{-1}"</tt>.</p></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 692 | <div class="paragraph"><p>As a further special case, you may use <tt>"A...B"</tt> as a shortcut for the |
| Junio C Hamano | e32ec8b | 2010-06-02 23:32:31 | [diff] [blame] | 693 | merge base of <tt>A</tt> and <tt>B</tt> if there is exactly one merge base. You can |
| 694 | leave out at most one of <tt>A</tt> and <tt>B</tt>, in which case it defaults to <tt>HEAD</tt>.</p></div> |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 695 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 696 | <dt class="hdlist1"> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 697 | <new_branch> |
| 698 | </dt> |
| 699 | <dd> |
| 700 | <p> |
| 701 | Name for the new branch. |
| 702 | </p> |
| 703 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 704 | <dt class="hdlist1"> |
| Junio C Hamano | 3bd66e9 | 2009-04-18 06:17:56 | [diff] [blame] | 705 | <start_point> |
| 706 | </dt> |
| 707 | <dd> |
| 708 | <p> |
| 709 | The name of a commit at which to start the new branch; see |
| 710 | <a href="git-branch.html">git-branch(1)</a> for details. Defaults to HEAD. |
| 711 | </p> |
| 712 | </dd> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 713 | <dt class="hdlist1"> |
| Junio C Hamano | b4a9ede | 2009-04-08 07:36:32 | [diff] [blame] | 714 | <tree-ish> |
| 715 | </dt> |
| 716 | <dd> |
| 717 | <p> |
| 718 | Tree to checkout from (when paths are given). If not specified, |
| 719 | the index will be used. |
| 720 | </p> |
| 721 | </dd> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 722 | </dl></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 723 | </div> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 724 | <h2 id="_detached_head">DETACHED HEAD</h2> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 725 | <div class="sectionbody"> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 726 | <div class="paragraph"><p>HEAD normally refers to a named branch (e.g. <em>master</em>). Meanwhile, each |
| 727 | branch refers to a specific commit. Let’s look at a repo with three |
| 728 | commits, one of them tagged, and with branch <em>master</em> checked out:</p></div> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 729 | <div class="listingblock"> |
| 730 | <div class="content"> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 731 | <pre><tt> HEAD (refers to branch 'master') |
| 732 | | |
| 733 | v |
| 734 | a---b---c branch 'master' (refers to commit 'c') |
| 735 | ^ |
| 736 | | |
| 737 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 738 | </div></div> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 739 | <div class="paragraph"><p>When a commit is created in this state, the branch is updated to refer to |
| 740 | the new commit. Specifically, <em>git commit</em> creates a new commit <em>d</em>, whose |
| 741 | parent is commit <em>c</em>, and then updates branch <em>master</em> to refer to new |
| 742 | commit <em>d</em>. HEAD still refers to branch <em>master</em> and so indirectly now refers |
| 743 | to commit <em>d</em>:</p></div> |
| Junio C Hamano | 9d52e57 | 2007-02-13 23:48:20 | [diff] [blame] | 744 | <div class="listingblock"> |
| 745 | <div class="content"> |
| Junio C Hamano | 63c2bc9 | 2011-02-28 06:41:28 | [diff] [blame] | 746 | <pre><tt>$ edit; git add; git commit |
| 747 | |
| 748 | HEAD (refers to branch 'master') |
| 749 | | |
| 750 | v |
| 751 | a---b---c---d branch 'master' (refers to commit 'd') |
| 752 | ^ |
| 753 | | |
| 754 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| 755 | </div></div> |
| 756 | <div class="paragraph"><p>It is sometimes useful to be able to checkout a commit that is not at |
| 757 | the tip of any named branch, or even to create a new commit that is not |
| 758 | referenced by a named branch. Let’s look at what happens when we |
| 759 | checkout commit <em>b</em> (here we show two ways this may be done):</p></div> |
| 760 | <div class="listingblock"> |
| 761 | <div class="content"> |
| 762 | <pre><tt>$ git checkout v2.0 # or |
| 763 | $ git checkout master^^ |
| 764 | |
| 765 | HEAD (refers to commit 'b') |
| 766 | | |
| 767 | v |
| 768 | a---b---c---d branch 'master' (refers to commit 'd') |
| 769 | ^ |
| 770 | | |
| 771 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| 772 | </div></div> |
| 773 | <div class="paragraph"><p>Notice that regardless of which checkout command we use, HEAD now refers |
| 774 | directly to commit <em>b</em>. This is known as being in detached HEAD state. |
| 775 | It means simply that HEAD refers to a specific commit, as opposed to |
| 776 | referring to a named branch. Let’s see what happens when we create a commit:</p></div> |
| 777 | <div class="listingblock"> |
| 778 | <div class="content"> |
| 779 | <pre><tt>$ edit; git add; git commit |
| 780 | |
| 781 | HEAD (refers to commit 'e') |
| 782 | | |
| 783 | v |
| 784 | e |
| 785 | / |
| 786 | a---b---c---d branch 'master' (refers to commit 'd') |
| 787 | ^ |
| 788 | | |
| 789 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| 790 | </div></div> |
| 791 | <div class="paragraph"><p>There is now a new commit <em>e</em>, but it is referenced only by HEAD. We can |
| 792 | of course add yet another commit in this state:</p></div> |
| 793 | <div class="listingblock"> |
| 794 | <div class="content"> |
| 795 | <pre><tt>$ edit; git add; git commit |
| 796 | |
| 797 | HEAD (refers to commit 'f') |
| 798 | | |
| 799 | v |
| 800 | e---f |
| 801 | / |
| 802 | a---b---c---d branch 'master' (refers to commit 'd') |
| 803 | ^ |
| 804 | | |
| 805 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| 806 | </div></div> |
| 807 | <div class="paragraph"><p>In fact, we can perform all the normal git operations. But, let’s look |
| 808 | at what happens when we then checkout master:</p></div> |
| 809 | <div class="listingblock"> |
| 810 | <div class="content"> |
| 811 | <pre><tt>$ git checkout master |
| 812 | |
| 813 | HEAD (refers to branch 'master') |
| 814 | e---f | |
| 815 | / v |
| 816 | a---b---c---d branch 'master' (refers to commit 'd') |
| 817 | ^ |
| 818 | | |
| 819 | tag 'v2.0' (refers to commit 'b')</tt></pre> |
| 820 | </div></div> |
| 821 | <div class="paragraph"><p>It is important to realize that at this point nothing refers to commit |
| 822 | <em>f</em>. Eventually commit <em>f</em> (and by extension commit <em>e</em>) will be deleted |
| 823 | by the routine git garbage collection process, unless we create a reference |
| 824 | before that happens. If we have not yet moved away from commit <em>f</em>, |
| 825 | any of these will create a reference to it:</p></div> |
| 826 | <div class="listingblock"> |
| 827 | <div class="content"> |
| 828 | <pre><tt>$ git checkout -b foo <b><1></b> |
| 829 | $ git branch foo <b><2></b> |
| 830 | $ git tag foo <b><3></b></tt></pre> |
| 831 | </div></div> |
| 832 | <div class="colist arabic"><ol> |
| 833 | <li> |
| 834 | <p> |
| 835 | creates a new branch <em>foo</em>, which refers to commit <em>f</em>, and then |
| 836 | updates HEAD to refer to branch <em>foo</em>. In other words, we’ll no longer |
| 837 | be in detached HEAD state after this command. |
| 838 | </p> |
| 839 | </li> |
| 840 | <li> |
| 841 | <p> |
| 842 | similarly creates a new branch <em>foo</em>, which refers to commit <em>f</em>, |
| 843 | but leaves HEAD detached. |
| 844 | </p> |
| 845 | </li> |
| 846 | <li> |
| 847 | <p> |
| 848 | creates a new tag <em>foo</em>, which refers to commit <em>f</em>, |
| 849 | leaving HEAD detached. |
| 850 | </p> |
| 851 | </li> |
| 852 | </ol></div> |
| 853 | <div class="paragraph"><p>If we have moved away from commit <em>f</em>, then we must first recover its object |
| 854 | name (typically by using git reflog), and then we can create a reference to |
| 855 | it. For example, to see the last two commits to which HEAD referred, we |
| 856 | can use either of these commands:</p></div> |
| 857 | <div class="listingblock"> |
| 858 | <div class="content"> |
| 859 | <pre><tt>$ git reflog -2 HEAD # or |
| 860 | $ git log -g -2 HEAD</tt></pre> |
| Junio C Hamano | 9d52e57 | 2007-02-13 23:48:20 | [diff] [blame] | 861 | </div></div> |
| Junio C Hamano | 4f9a605 | 2007-01-17 20:25:16 | [diff] [blame] | 862 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 863 | <h2 id="_examples">EXAMPLES</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 864 | <div class="sectionbody"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 865 | <div class="olist arabic"><ol class="arabic"> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 866 | <li> |
| 867 | <p> |
| 868 | The following sequence checks out the <tt>master</tt> branch, reverts |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 869 | the <tt>Makefile</tt> to two revisions back, deletes hello.c by |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 870 | mistake, and gets it back from the index. |
| 871 | </p> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 872 | <div class="listingblock"> |
| 873 | <div class="content"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 874 | <pre><tt>$ git checkout master <b><1></b> |
| 875 | $ git checkout master~2 Makefile <b><2></b> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 876 | $ rm -f hello.c |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 877 | $ git checkout hello.c <b><3></b></tt></pre> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 878 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 879 | <div class="colist arabic"><ol> |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 880 | <li> |
| 881 | <p> |
| 882 | switch branch |
| 883 | </p> |
| 884 | </li> |
| 885 | <li> |
| 886 | <p> |
| Junio C Hamano | 5705393 | 2009-03-11 08:48:32 | [diff] [blame] | 887 | take a file out of another commit |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 888 | </p> |
| 889 | </li> |
| 890 | <li> |
| 891 | <p> |
| Junio C Hamano | b4a9ede | 2009-04-08 07:36:32 | [diff] [blame] | 892 | restore hello.c from the index |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 893 | </p> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 894 | <div class="paragraph"><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] | 895 | step would be confused as an instruction to switch to that branch. |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 896 | You should instead write:</p></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 897 | <div class="listingblock"> |
| 898 | <div class="content"> |
| 899 | <pre><tt>$ git checkout -- hello.c</tt></pre> |
| 900 | </div></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 901 | </li> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 902 | </ol></div> |
| Junio C Hamano | c8d88c2 | 2006-04-29 07:02:01 | [diff] [blame] | 903 | </li> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 904 | <li> |
| 905 | <p> |
| Junio C Hamano | 5705393 | 2009-03-11 08:48:32 | [diff] [blame] | 906 | After working in the wrong branch, switching to the correct |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 907 | branch would be done using: |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 908 | </p> |
| 909 | <div class="listingblock"> |
| 910 | <div class="content"> |
| 911 | <pre><tt>$ git checkout mytopic</tt></pre> |
| 912 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 913 | <div class="paragraph"><p>However, your "wrong" branch and correct "mytopic" branch may |
| Junio C Hamano | 5705393 | 2009-03-11 08:48:32 | [diff] [blame] | 914 | differ in files that you have modified locally, in which case |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 915 | the above checkout would fail like this:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 916 | <div class="listingblock"> |
| 917 | <div class="content"> |
| 918 | <pre><tt>$ git checkout mytopic |
| Junio C Hamano | f2d3a37 | 2010-07-12 14:14:18 | [diff] [blame] | 919 | error: You have local changes to 'frotz'; not switching branches.</tt></pre> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 920 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 921 | <div class="paragraph"><p>You can give the <tt>-m</tt> flag to the command, which would try a |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 922 | three-way merge:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 923 | <div class="listingblock"> |
| 924 | <div class="content"> |
| 925 | <pre><tt>$ git checkout -m mytopic |
| 926 | Auto-merging frotz</tt></pre> |
| 927 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 928 | <div class="paragraph"><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] | 929 | 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] | 930 | changes you made since the tip of the new branch.</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 931 | </li> |
| 932 | <li> |
| 933 | <p> |
| 934 | When a merge conflict happens during switching branches with |
| 935 | the <tt>-m</tt> option, you would see something like this: |
| 936 | </p> |
| 937 | <div class="listingblock"> |
| 938 | <div class="content"> |
| 939 | <pre><tt>$ git checkout -m mytopic |
| 940 | Auto-merging frotz |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 941 | ERROR: Merge conflict in frotz |
| 942 | fatal: merge program failed</tt></pre> |
| 943 | </div></div> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 944 | <div class="paragraph"><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] | 945 | the previous example, as well as the changes in the conflicted |
| 946 | files. Edit and resolve the conflict and mark it resolved with |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 947 | <tt>git add</tt> as usual:</p></div> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 948 | <div class="listingblock"> |
| 949 | <div class="content"> |
| 950 | <pre><tt>$ edit frotz |
| Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 951 | $ git add frotz</tt></pre> |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 952 | </div></div> |
| 953 | </li> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 954 | </ol></div> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 955 | </div> |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 956 | <h2 id="_git">GIT</h2> |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 957 | <div class="sectionbody"> |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 958 | <div class="paragraph"><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] | 959 | </div> |
| 960 | <div id="footer"> |
| 961 | <div id="footer-text"> |
| Junio C Hamano | 9eb5835 | 2011-05-11 20:09:24 | [diff] [blame^] | 962 | Last updated 2011-05-11 20:08:54 UTC |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 963 | </div> |
| 964 | </div> |
| 965 | </body> |
| 966 | </html> |