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 | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 7.0.2" /> |
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 | |
| 19 | a { color: blue; } |
| 20 | a:visited { color: fuchsia; } |
| 21 | |
| 22 | em { |
| 23 | font-style: italic; |
| 24 | } |
| 25 | |
| 26 | strong { |
| 27 | font-weight: bold; |
| 28 | } |
| 29 | |
| 30 | tt { |
| 31 | color: navy; |
| 32 | } |
| 33 | |
| 34 | h1, h2, h3, h4, h5, h6 { |
| 35 | color: #527bbd; |
| 36 | font-family: sans-serif; |
| 37 | margin-top: 1.2em; |
| 38 | margin-bottom: 0.5em; |
| 39 | line-height: 1.3; |
| 40 | } |
| 41 | |
| 42 | h1 { |
| 43 | border-bottom: 2px solid silver; |
| 44 | } |
| 45 | h2 { |
| 46 | border-bottom: 2px solid silver; |
| 47 | padding-top: 0.5em; |
| 48 | } |
| 49 | |
| 50 | div.sectionbody { |
| 51 | font-family: serif; |
| 52 | margin-left: 0; |
| 53 | } |
| 54 | |
| 55 | hr { |
| 56 | border: 1px solid silver; |
| 57 | } |
| 58 | |
| 59 | p { |
| 60 | margin-top: 0.5em; |
| 61 | margin-bottom: 0.5em; |
| 62 | } |
| 63 | |
| 64 | pre { |
| 65 | padding: 0; |
| 66 | margin: 0; |
| 67 | } |
| 68 | |
| 69 | span#author { |
| 70 | color: #527bbd; |
| 71 | font-family: sans-serif; |
| 72 | font-weight: bold; |
| 73 | font-size: 1.2em; |
| 74 | } |
| 75 | span#email { |
| 76 | } |
| 77 | span#revision { |
| 78 | font-family: sans-serif; |
| 79 | } |
| 80 | |
| 81 | div#footer { |
| 82 | font-family: sans-serif; |
| 83 | font-size: small; |
| 84 | border-top: 2px solid silver; |
| 85 | padding-top: 0.5em; |
| 86 | margin-top: 4.0em; |
| 87 | } |
| 88 | div#footer-text { |
| 89 | float: left; |
| 90 | padding-bottom: 0.5em; |
| 91 | } |
| 92 | div#footer-badges { |
| 93 | float: right; |
| 94 | padding-bottom: 0.5em; |
| 95 | } |
| 96 | |
| 97 | div#preamble, |
| 98 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 99 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 100 | div.admonitionblock { |
| 101 | margin-right: 10%; |
| 102 | margin-top: 1.5em; |
| 103 | margin-bottom: 1.5em; |
| 104 | } |
| 105 | div.admonitionblock { |
| 106 | margin-top: 2.5em; |
| 107 | margin-bottom: 2.5em; |
| 108 | } |
| 109 | |
| 110 | div.content { /* Block element content. */ |
| 111 | padding: 0; |
| 112 | } |
| 113 | |
| 114 | /* Block element titles. */ |
| 115 | div.title, caption.title { |
| 116 | font-family: sans-serif; |
| 117 | font-weight: bold; |
| 118 | text-align: left; |
| 119 | margin-top: 1.0em; |
| 120 | margin-bottom: 0.5em; |
| 121 | } |
| 122 | div.title + * { |
| 123 | margin-top: 0; |
| 124 | } |
| 125 | |
| 126 | td div.title:first-child { |
| 127 | margin-top: 0.0em; |
| 128 | } |
| 129 | div.content div.title:first-child { |
| 130 | margin-top: 0.0em; |
| 131 | } |
| 132 | div.content + div.title { |
| 133 | margin-top: 0.0em; |
| 134 | } |
| 135 | |
| 136 | div.sidebarblock > div.content { |
| 137 | background: #ffffee; |
| 138 | border: 1px solid silver; |
| 139 | padding: 0.5em; |
| 140 | } |
| 141 | |
| 142 | div.listingblock > div.content { |
| 143 | border: 1px solid silver; |
| 144 | background: #f4f4f4; |
| 145 | padding: 0.5em; |
| 146 | } |
| 147 | |
| 148 | div.quoteblock > div.content { |
| 149 | padding-left: 2.0em; |
| 150 | } |
| 151 | div.quoteblock .attribution { |
| 152 | text-align: right; |
| 153 | } |
| 154 | |
| 155 | div.admonitionblock .icon { |
| 156 | vertical-align: top; |
| 157 | font-size: 1.1em; |
| 158 | font-weight: bold; |
| 159 | text-decoration: underline; |
| 160 | color: #527bbd; |
| 161 | padding-right: 0.5em; |
| 162 | } |
| 163 | div.admonitionblock td.content { |
| 164 | padding-left: 0.5em; |
| 165 | border-left: 2px solid silver; |
| 166 | } |
| 167 | |
| 168 | div.exampleblock > div.content { |
| 169 | border-left: 2px solid silver; |
| 170 | padding: 0.5em; |
| 171 | } |
| 172 | |
| 173 | div.verseblock div.content { |
| 174 | white-space: pre; |
| 175 | } |
| 176 | |
| 177 | div.imageblock div.content { padding-left: 0; } |
| 178 | div.imageblock img { border: 1px solid silver; } |
| 179 | span.image img { border-style: none; } |
| 180 | |
| 181 | dl { |
| 182 | margin-top: 0.8em; |
| 183 | margin-bottom: 0.8em; |
| 184 | } |
| 185 | dt { |
| 186 | margin-top: 0.5em; |
| 187 | margin-bottom: 0; |
| 188 | font-style: italic; |
| 189 | } |
| 190 | dd > *:first-child { |
| 191 | margin-top: 0; |
| 192 | } |
| 193 | |
| 194 | ul, ol { |
| 195 | list-style-position: outside; |
| 196 | } |
| 197 | ol.olist2 { |
| 198 | list-style-type: lower-alpha; |
| 199 | } |
| 200 | |
| 201 | div.tableblock > table { |
| 202 | border-color: #527bbd; |
| 203 | border-width: 3px; |
| 204 | } |
| 205 | thead { |
| 206 | font-family: sans-serif; |
| 207 | font-weight: bold; |
| 208 | } |
| 209 | tfoot { |
| 210 | font-weight: bold; |
| 211 | } |
| 212 | |
| 213 | div.hlist { |
| 214 | margin-top: 0.8em; |
| 215 | margin-bottom: 0.8em; |
| 216 | } |
| 217 | td.hlist1 { |
| 218 | vertical-align: top; |
| 219 | font-style: italic; |
| 220 | padding-right: 0.8em; |
| 221 | } |
| 222 | td.hlist2 { |
| 223 | vertical-align: top; |
| 224 | } |
| 225 | |
| 226 | @media print { |
| 227 | div#footer-badges { display: none; } |
| 228 | } |
| 229 | include::./stylesheets/xhtml11-manpage.css[] |
| 230 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 231 | |
| 232 | div.sidebar-content { |
| 233 | background: #ffffee; |
| 234 | border: 1px solid silver; |
| 235 | padding: 0.5em; |
| 236 | } |
| 237 | div.sidebar-title, div.image-title { |
| 238 | font-family: sans-serif; |
| 239 | font-weight: bold; |
| 240 | margin-top: 0.0em; |
| 241 | margin-bottom: 0.5em; |
| 242 | } |
| 243 | |
| 244 | div.listingblock div.content { |
| 245 | border: 1px solid silver; |
| 246 | background: #f4f4f4; |
| 247 | padding: 0.5em; |
| 248 | } |
| 249 | |
| 250 | div.quoteblock-content { |
| 251 | padding-left: 2.0em; |
| 252 | } |
| 253 | |
| 254 | div.exampleblock-content { |
| 255 | border-left: 2px solid silver; |
| 256 | padding-left: 0.5em; |
| 257 | } |
| 258 | </style> |
| 259 | <title>git-merge(1)</title> |
| 260 | </head> |
| 261 | <body> |
| 262 | <div id="header"> |
| 263 | <h1> |
| 264 | git-merge(1) Manual Page |
| 265 | </h1> |
| 266 | <h2>NAME</h2> |
| 267 | <div class="sectionbody"> |
| 268 | <p>git-merge - |
| 269 | Grand Unified Merge Driver |
| 270 | </p> |
| 271 | </div> |
| 272 | </div> |
| 273 | <h2>SYNOPSIS</h2> |
| 274 | <div class="sectionbody"> |
| 275 | <p><em>git-merge</em> [-n] [--no-commit] [-s <strategy>]… <msg> <head> <remote> <remote>…</p> |
| 276 | </div> |
| 277 | <h2>DESCRIPTION</h2> |
| 278 | <div class="sectionbody"> |
| 279 | <p>This is the top-level user interface to the merge machinery |
| 280 | which drives multiple merge strategy scripts.</p> |
| 281 | </div> |
| 282 | <h2>OPTIONS</h2> |
| 283 | <div class="sectionbody"> |
| 284 | <dl> |
| 285 | <dt> |
| 286 | -n, --no-summary |
| 287 | </dt> |
| 288 | <dd> |
| 289 | <p> |
| 290 | Do not show diffstat at the end of the merge. |
| 291 | </p> |
| 292 | </dd> |
| 293 | <dt> |
| 294 | --no-commit |
| 295 | </dt> |
| 296 | <dd> |
| 297 | <p> |
| 298 | Perform the merge but pretend the merge failed and do |
| 299 | not autocommit, to give the user a chance to inspect and |
| 300 | further tweak the merge result before committing. |
| 301 | </p> |
| 302 | </dd> |
| 303 | <dt> |
Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 304 | --squash |
| 305 | </dt> |
| 306 | <dd> |
| 307 | <p> |
| 308 | Produce the working tree and index state as if a real |
| 309 | merge happened, but do not actually make a commit or |
| 310 | move the <tt>HEAD</tt>, nor record <tt>$GIT_DIR/MERGE_HEAD</tt> to |
| 311 | cause the next <tt>git commit</tt> command to create a merge |
| 312 | commit. This allows you to create a single commit on |
| 313 | top of the current branch whose effect is the same as |
| 314 | merging another branch (or more in case of an octopus). |
| 315 | </p> |
| 316 | </dd> |
| 317 | <dt> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 318 | -s <strategy>, --strategy=<strategy> |
| 319 | </dt> |
| 320 | <dd> |
| 321 | <p> |
| 322 | Use the given merge strategy; can be supplied more than |
| 323 | once to specify them in the order they should be tried. |
| 324 | If there is no <tt>-s</tt> option, a built-in list of strategies |
| 325 | is used instead (<tt>git-merge-recursive</tt> when merging a single |
| 326 | head, <tt>git-merge-octopus</tt> otherwise). |
| 327 | </p> |
| 328 | </dd> |
| 329 | <dt> |
| 330 | <msg> |
| 331 | </dt> |
| 332 | <dd> |
| 333 | <p> |
| 334 | The commit message to be used for the merge commit (in case |
| 335 | it is created). The <tt>git-fmt-merge-msg</tt> script can be used |
| 336 | to give a good default for automated <tt>git-merge</tt> invocations. |
| 337 | </p> |
| 338 | </dd> |
| 339 | <dt> |
| 340 | <head> |
| 341 | </dt> |
| 342 | <dd> |
| 343 | <p> |
| 344 | our branch head commit. |
| 345 | </p> |
| 346 | </dd> |
| 347 | <dt> |
| 348 | <remote> |
| 349 | </dt> |
| 350 | <dd> |
| 351 | <p> |
| 352 | other branch head merged into our branch. You need at |
| 353 | least one <remote>. Specifying more than one <remote> |
| 354 | obviously means you are trying an Octopus. |
| 355 | </p> |
| 356 | </dd> |
| 357 | </dl> |
| 358 | </div> |
| 359 | <h2>MERGE STRATEGIES</h2> |
| 360 | <div class="sectionbody"> |
| 361 | <dl> |
| 362 | <dt> |
| 363 | resolve |
| 364 | </dt> |
| 365 | <dd> |
| 366 | <p> |
| 367 | This can only resolve two heads (i.e. the current branch |
| 368 | and another branch you pulled from) using 3-way merge |
| 369 | algorithm. It tries to carefully detect criss-cross |
| 370 | merge ambiguities and is considered generally safe and |
| 371 | fast. |
| 372 | </p> |
| 373 | </dd> |
| 374 | <dt> |
| 375 | recursive |
| 376 | </dt> |
| 377 | <dd> |
| 378 | <p> |
| 379 | This can only resolve two heads using 3-way merge |
| 380 | algorithm. When there are more than one common |
| 381 | ancestors that can be used for 3-way merge, it creates a |
| 382 | merged tree of the common ancestors and uses that as |
| 383 | the reference tree for the 3-way merge. This has been |
| 384 | reported to result in fewer merge conflicts without |
| 385 | causing mis-merges by tests done on actual merge commits |
| 386 | taken from Linux 2.6 kernel development history. |
| 387 | Additionally this can detect and handle merges involving |
| 388 | renames. This is the default merge strategy when |
| 389 | pulling or merging one branch. |
| 390 | </p> |
| 391 | </dd> |
| 392 | <dt> |
| 393 | octopus |
| 394 | </dt> |
| 395 | <dd> |
| 396 | <p> |
| 397 | This resolves more than two-head case, but refuses to do |
| 398 | complex merge that needs manual resolution. It is |
| 399 | primarily meant to be used for bundling topic branch |
| 400 | heads together. This is the default merge strategy when |
| 401 | pulling or merging more than one branches. |
| 402 | </p> |
| 403 | </dd> |
| 404 | <dt> |
| 405 | ours |
| 406 | </dt> |
| 407 | <dd> |
| 408 | <p> |
| 409 | This resolves any number of heads, but the result of the |
| 410 | merge is always the current branch head. It is meant to |
| 411 | be used to supersede old development history of side |
| 412 | branches. |
| 413 | </p> |
| 414 | </dd> |
| 415 | </dl> |
| 416 | <p>If you tried a merge which resulted in a complex conflicts and |
| 417 | would want to start over, you can recover with |
| 418 | <a href="git-reset.html">git-reset(1)</a>.</p> |
| 419 | </div> |
| 420 | <h2>HOW MERGE WORKS</h2> |
| 421 | <div class="sectionbody"> |
| 422 | <p>A merge is always between the current <tt>HEAD</tt> and one or more |
| 423 | remote branch heads, and the index file must exactly match the |
| 424 | tree of <tt>HEAD</tt> commit (i.e. the contents of the last commit) when |
| 425 | it happens. In other words, <tt>git-diff --cached HEAD</tt> must |
| 426 | report no changes.</p> |
| 427 | <div class="admonitionblock"> |
| 428 | <table><tr> |
| 429 | <td class="icon"> |
| 430 | <div class="title">Note</div> |
| 431 | </td> |
| 432 | <td class="content">This is a bit of lie. In certain special cases, your index are |
| 433 | allowed to be different from the tree of <tt>HEAD</tt> commit. The most |
| 434 | notable case is when your <tt>HEAD</tt> commit is already ahead of what |
| 435 | is being merged, in which case your index can have arbitrary |
| 436 | difference from your <tt>HEAD</tt> commit. Otherwise, your index entries |
| 437 | are allowed have differences from your <tt>HEAD</tt> commit that match |
| 438 | the result of trivial merge (e.g. you received the same patch |
| 439 | from external source to produce the same result as what you are |
| 440 | merging). For example, if a path did not exist in the common |
| 441 | ancestor and your head commit but exists in the tree you are |
| 442 | merging into your repository, and if you already happen to have |
| 443 | that path exactly in your index, the merge does not have to |
| 444 | fail.</td> |
| 445 | </tr></table> |
| 446 | </div> |
| 447 | <p>Otherwise, merge will refuse to do any harm to your repository |
| 448 | (that is, it may fetch the objects from remote, and it may even |
| 449 | update the local branch used to keep track of the remote branch |
| 450 | with <tt>git pull remote rbranch:lbranch</tt>, but your working tree, |
| 451 | <tt>.git/HEAD</tt> pointer and index file are left intact).</p> |
| 452 | <p>You may have local modifications in the working tree files. In |
| 453 | other words, <tt>git-diff</tt> is allowed to report changes. |
| 454 | However, the merge uses your working tree as the working area, |
| 455 | and in order to prevent the merge operation from losing such |
| 456 | changes, it makes sure that they do not interfere with the |
| 457 | merge. Those complex tables in read-tree documentation define |
| 458 | what it means for a path to "interfere with the merge". And if |
| 459 | your local modifications interfere with the merge, again, it |
| 460 | stops before touching anything.</p> |
| 461 | <p>So in the above two "failed merge" case, you do not have to |
Junio C Hamano | 51c2ab0 | 2006-07-09 20:38:54 | [diff] [blame] | 462 | worry about loss of data --- you simply were not ready to do |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 463 | a merge, so no merge happened at all. You may want to finish |
| 464 | whatever you were in the middle of doing, and retry the same |
| 465 | pull after you are done and ready.</p> |
| 466 | <p>When things cleanly merge, these things happen:</p> |
| 467 | <ol> |
| 468 | <li> |
| 469 | <p> |
| 470 | the results are updated both in the index file and in your |
| 471 | working tree, |
| 472 | </p> |
| 473 | </li> |
| 474 | <li> |
| 475 | <p> |
| 476 | index file is written out as a tree, |
| 477 | </p> |
| 478 | </li> |
| 479 | <li> |
| 480 | <p> |
| 481 | the tree gets committed, and |
| 482 | </p> |
| 483 | </li> |
| 484 | <li> |
| 485 | <p> |
| 486 | the <tt>HEAD</tt> pointer gets advanced. |
| 487 | </p> |
| 488 | </li> |
| 489 | </ol> |
| 490 | <p>Because of 2., we require that the original state of the index |
| 491 | file to match exactly the current <tt>HEAD</tt> commit; otherwise we |
| 492 | will write out your local changes already registered in your |
| 493 | index file along with the merge result, which is not good. |
| 494 | Because 1. involves only the paths different between your |
| 495 | branch and the remote branch you are pulling from during the |
| 496 | merge (which is typically a fraction of the whole tree), you can |
| 497 | have local modifications in your working tree as long as they do |
| 498 | not overlap with what the merge updates.</p> |
| 499 | <p>When there are conflicts, these things happen:</p> |
| 500 | <ol> |
| 501 | <li> |
| 502 | <p> |
| 503 | <tt>HEAD</tt> stays the same. |
| 504 | </p> |
| 505 | </li> |
| 506 | <li> |
| 507 | <p> |
| 508 | Cleanly merged paths are updated both in the index file and |
| 509 | in your working tree. |
| 510 | </p> |
| 511 | </li> |
| 512 | <li> |
| 513 | <p> |
| 514 | For conflicting paths, the index file records up to three |
| 515 | versions; stage1 stores the version from the common ancestor, |
| 516 | stage2 from <tt>HEAD</tt>, and stage3 from the remote branch (you |
| 517 | can inspect the stages with <tt>git-ls-files -u</tt>). The working |
| 518 | tree files have the result of "merge" program; i.e. 3-way |
| 519 | merge result with familiar conflict markers <tt><<< === >>></tt>. |
| 520 | </p> |
| 521 | </li> |
| 522 | <li> |
| 523 | <p> |
| 524 | No other changes are done. In particular, the local |
| 525 | modifications you had before you started merge will stay the |
| 526 | same and the index entries for them stay as they were, |
| 527 | i.e. matching <tt>HEAD</tt>. |
| 528 | </p> |
| 529 | </li> |
| 530 | </ol> |
| 531 | <p>After seeing a conflict, you can do two things:</p> |
| 532 | <ul> |
| 533 | <li> |
| 534 | <p> |
| 535 | Decide not to merge. The only clean-up you need are to reset |
| 536 | the index file to the <tt>HEAD</tt> commit to reverse 2. and to clean |
| 537 | up working tree changes made by 2. and 3.; <tt>git-reset</tt> can |
| 538 | be used for this. |
| 539 | </p> |
| 540 | </li> |
| 541 | <li> |
| 542 | <p> |
| 543 | Resolve the conflicts. <tt>git-diff</tt> would report only the |
| 544 | conflicting paths because of the above 2. and 3.. Edit the |
| 545 | working tree files into a desirable shape, <tt>git-update-index</tt> |
| 546 | them, to make the index file contain what the merge result |
| 547 | should be, and run <tt>git-commit</tt> to commit the result. |
| 548 | </p> |
| 549 | </li> |
| 550 | </ul> |
| 551 | </div> |
| 552 | <h2>SEE ALSO</h2> |
| 553 | <div class="sectionbody"> |
| 554 | <p><a href="git-fmt-merge-msg.html">git-fmt-merge-msg(1)</a>, <a href="git-pull.html">git-pull(1)</a></p> |
| 555 | </div> |
| 556 | <h2>Author</h2> |
| 557 | <div class="sectionbody"> |
| 558 | <p>Written by Junio C Hamano <junkio@cox.net></p> |
| 559 | </div> |
| 560 | <h2>Documentation</h2> |
| 561 | <div class="sectionbody"> |
| 562 | <p>Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.</p> |
| 563 | </div> |
| 564 | <h2>GIT</h2> |
| 565 | <div class="sectionbody"> |
| 566 | <p>Part of the <a href="git.html">git(7)</a> suite</p> |
| 567 | </div> |
| 568 | <div id="footer"> |
| 569 | <div id="footer-text"> |
Junio C Hamano | 7ccb9fd | 2006-07-15 01:38:40 | [diff] [blame] | 570 | Last updated 15-Jul-2006 01:37:56 UTC |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 571 | </div> |
| 572 | </div> |
| 573 | </body> |
| 574 | </html> |