1GIT-MERGE(1) Git Manual GIT-MERGE(1)
2
3
4
6 git-merge - Join two or more development histories together
7
9 git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
10 [-s <strategy>] [-X <strategy-option>]
11 [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
12 git merge <msg> HEAD <commit>...
13 git merge --abort
14
15
17 Incorporates changes from the named commits (since the time their
18 histories diverged from the current branch) into the current branch.
19 This command is used by git pull to incorporate changes from another
20 repository and can be used by hand to merge changes from one branch
21 into another.
22
23 Assume the following history exists and the current branch is "master":
24
25 A---B---C topic
26 /
27 D---E---F---G master
28
29
30 Then "git merge topic" will replay the changes made on the topic branch
31 since it diverged from master (i.e., E) until its current commit (C) on
32 top of master, and record the result in a new commit along with the
33 names of the two parent commits and a log message from the user
34 describing the changes.
35
36 A---B---C topic
37 / \
38 D---E---F---G---H master
39
40
41 The second syntax (<msg> HEAD <commit>...) is supported for historical
42 reasons. Do not use it from the command line or in new scripts. It is
43 the same as git merge -m <msg> <commit>....
44
45 The third syntax ("git merge --abort") can only be run after the merge
46 has resulted in conflicts. git merge --abort will abort the merge
47 process and try to reconstruct the pre-merge state. However, if there
48 were uncommitted changes when the merge started (and especially if
49 those changes were further modified after the merge was started), git
50 merge --abort will in some cases be unable to reconstruct the original
51 (pre-merge) changes. Therefore:
52
53 Warning: Running git merge with uncommitted changes is discouraged:
54 while possible, it leaves you in a state that is hard to back out of in
55 the case of a conflict.
56
58 --commit, --no-commit
59 Perform the merge and commit the result. This option can be used to
60 override --no-commit.
61
62 With --no-commit perform the merge but pretend the merge failed and
63 do not autocommit, to give the user a chance to inspect and further
64 tweak the merge result before committing.
65
66 --edit, --no-edit
67 Invoke an editor before committing successful mechanical merge to
68 further edit the auto-generated merge message, so that the user can
69 explain and justify the merge. The --no-edit option can be used to
70 accept the auto-generated message (this is generally discouraged).
71 The --edit option is still useful if you are giving a draft message
72 with the -m option from the command line and want to edit it in the
73 editor.
74
75 Older scripts may depend on the historical behaviour of not
76 allowing the user to edit the merge log message. They will see an
77 editor opened when they run git merge. To make it easier to adjust
78 such scripts to the updated behaviour, the environment variable
79 GIT_MERGE_AUTOEDIT can be set to no at the beginning of them.
80
81 --ff
82 When the merge resolves as a fast-forward, only update the branch
83 pointer, without creating a merge commit. This is the default
84 behavior.
85
86 --no-ff
87 Create a merge commit even when the merge resolves as a
88 fast-forward. This is the default behaviour when merging an
89 annotated (and possibly signed) tag.
90
91 --ff-only
92 Refuse to merge and exit with a non-zero status unless the current
93 HEAD is already up-to-date or the merge can be resolved as a
94 fast-forward.
95
96 --log[=<n>], --no-log
97 In addition to branch names, populate the log message with one-line
98 descriptions from at most <n> actual commits that are being merged.
99 See also git-fmt-merge-msg(1).
100
101 With --no-log do not list one-line descriptions from the actual
102 commits being merged.
103
104 --stat, -n, --no-stat
105 Show a diffstat at the end of the merge. The diffstat is also
106 controlled by the configuration option merge.stat.
107
108 With -n or --no-stat do not show a diffstat at the end of the
109 merge.
110
111 --squash, --no-squash
112 Produce the working tree and index state as if a real merge
113 happened (except for the merge information), but do not actually
114 make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to
115 cause the next git commit command to create a merge commit. This
116 allows you to create a single commit on top of the current branch
117 whose effect is the same as merging another branch (or more in case
118 of an octopus).
119
120 With --no-squash perform the merge and commit the result. This
121 option can be used to override --squash.
122
123 -s <strategy>, --strategy=<strategy>
124 Use the given merge strategy; can be supplied more than once to
125 specify them in the order they should be tried. If there is no -s
126 option, a built-in list of strategies is used instead (git
127 merge-recursive when merging a single head, git merge-octopus
128 otherwise).
129
130 -X <option>, --strategy-option=<option>
131 Pass merge strategy specific option through to the merge strategy.
132
133 --verify-signatures, --no-verify-signatures
134 Verify that the commits being merged have good and trusted GPG
135 signatures and abort the merge in case they do not.
136
137 --summary, --no-summary
138 Synonyms to --stat and --no-stat; these are deprecated and will be
139 removed in the future.
140
141 -q, --quiet
142 Operate quietly. Implies --no-progress.
143
144 -v, --verbose
145 Be verbose.
146
147 --progress, --no-progress
148 Turn progress on/off explicitly. If neither is specified, progress
149 is shown if standard error is connected to a terminal. Note that
150 not all merge strategies may support progress reporting.
151
152 -m <msg>
153 Set the commit message to be used for the merge commit (in case one
154 is created).
155
156 If --log is specified, a shortlog of the commits being merged will
157 be appended to the specified message.
158
159 The git fmt-merge-msg command can be used to give a good default
160 for automated git merge invocations.
161
162 --[no-]rerere-autoupdate
163 Allow the rerere mechanism to update the index with the result of
164 auto-conflict resolution if possible.
165
166 --abort
167 Abort the current conflict resolution process, and try to
168 reconstruct the pre-merge state.
169
170 If there were uncommitted worktree changes present when the merge
171 started, git merge --abort will in some cases be unable to
172 reconstruct these changes. It is therefore recommended to always
173 commit or stash your changes before running git merge.
174
175 git merge --abort is equivalent to git reset --merge when
176 MERGE_HEAD is present.
177
178 <commit>...
179 Commits, usually other branch heads, to merge into our branch.
180 Specifying more than one commit will create a merge with more than
181 two parents (affectionately called an Octopus merge).
182
183 If no commit is given from the command line, and if
184 merge.defaultToUpstream configuration variable is set, merge the
185 remote-tracking branches that the current branch is configured to
186 use as its upstream. See also the configuration section of this
187 manual page.
188
190 Before applying outside changes, you should get your own work in good
191 shape and committed locally, so it will not be clobbered if there are
192 conflicts. See also git-stash(1). git pull and git merge will stop
193 without doing anything when local uncommitted changes overlap with
194 files that git pull/git merge may need to update.
195
196 To avoid recording unrelated changes in the merge commit, git pull and
197 git merge will also abort if there are any changes registered in the
198 index relative to the HEAD commit. (One exception is when the changed
199 index entries are in the state that would result from the merge
200 already.)
201
202 If all named commits are already ancestors of HEAD, git merge will exit
203 early with the message "Already up-to-date."
204
206 Often the current branch head is an ancestor of the named commit. This
207 is the most common case especially when invoked from git pull: you are
208 tracking an upstream repository, you have committed no local changes,
209 and now you want to update to a newer upstream revision. In this case,
210 a new commit is not needed to store the combined history; instead, the
211 HEAD (along with the index) is updated to point at the named commit,
212 without creating an extra merge commit.
213
214 This behavior can be suppressed with the --no-ff option.
215
217 Except in a fast-forward merge (see above), the branches to be merged
218 must be tied together by a merge commit that has both of them as its
219 parents.
220
221 A merged version reconciling the changes from all branches to be merged
222 is committed, and your HEAD, index, and working tree are updated to it.
223 It is possible to have modifications in the working tree as long as
224 they do not overlap; the update will preserve them.
225
226 When it is not obvious how to reconcile the changes, the following
227 happens:
228
229 1. The HEAD pointer stays the same.
230
231 2. The MERGE_HEAD ref is set to point to the other branch head.
232
233 3. Paths that merged cleanly are updated both in the index file and in
234 your working tree.
235
236 4. For conflicting paths, the index file records up to three versions:
237 stage 1 stores the version from the common ancestor, stage 2 from
238 HEAD, and stage 3 from MERGE_HEAD (you can inspect the stages with
239 git ls-files -u). The working tree files contain the result of the
240 "merge" program; i.e. 3-way merge results with familiar conflict
241 markers <<<===>>>.
242
243 5. No other changes are made. In particular, the local modifications
244 you had before you started merge will stay the same and the index
245 entries for them stay as they were, i.e. matching HEAD.
246
247 If you tried a merge which resulted in complex conflicts and want to
248 start over, you can recover with git merge --abort.
249
251 When merging an annotated (and possibly signed) tag, Git always creates
252 a merge commit even if a fast-forward merge is possible, and the commit
253 message template is prepared with the tag message. Additionally, if the
254 tag is signed, the signature check is reported as a comment in the
255 message template. See also git-tag(1).
256
257 When you want to just integrate with the work leading to the commit
258 that happens to be tagged, e.g. synchronizing with an upstream release
259 point, you may not want to make an unnecessary merge commit.
260
261 In such a case, you can "unwrap" the tag yourself before feeding it to
262 git merge, or pass --ff-only when you do not have any work on your own.
263 e.g.
264
265 --- git fetch origin git merge v1.2.3^0 git merge --ff-only v1.2.3 ---
266
268 During a merge, the working tree files are updated to reflect the
269 result of the merge. Among the changes made to the common ancestor’s
270 version, non-overlapping ones (that is, you changed an area of the file
271 while the other side left that area intact, or vice versa) are
272 incorporated in the final result verbatim. When both sides made changes
273 to the same area, however, Git cannot randomly pick one side over the
274 other, and asks you to resolve it by leaving what both sides did to
275 that area.
276
277 By default, Git uses the same style as the one used by the "merge"
278 program from the RCS suite to present such a conflicted hunk, like
279 this:
280
281 Here are lines that are either unchanged from the common
282 ancestor, or cleanly resolved because only one side changed.
283 <<<<<<< yours:sample.txt
284 Conflict resolution is hard;
285 let's go shopping.
286 =======
287 Git makes conflict resolution easy.
288 >>>>>>> theirs:sample.txt
289 And here is another line that is cleanly resolved or unmodified.
290
291
292 The area where a pair of conflicting changes happened is marked with
293 markers <<<<<<<, =======, and >>>>>>>. The part before the ======= is
294 typically your side, and the part afterwards is typically their side.
295
296 The default format does not show what the original said in the
297 conflicting area. You cannot tell how many lines are deleted and
298 replaced with Barbie’s remark on your side. The only thing you can tell
299 is that your side wants to say it is hard and you’d prefer to go
300 shopping, while the other side wants to claim it is easy.
301
302 An alternative style can be used by setting the "merge.conflictstyle"
303 configuration variable to "diff3". In "diff3" style, the above conflict
304 may look like this:
305
306 Here are lines that are either unchanged from the common
307 ancestor, or cleanly resolved because only one side changed.
308 <<<<<<< yours:sample.txt
309 Conflict resolution is hard;
310 let's go shopping.
311 |||||||
312 Conflict resolution is hard.
313 =======
314 Git makes conflict resolution easy.
315 >>>>>>> theirs:sample.txt
316 And here is another line that is cleanly resolved or unmodified.
317
318
319 In addition to the <<<<<<<, =======, and >>>>>>> markers, it uses
320 another ||||||| marker that is followed by the original text. You can
321 tell that the original just stated a fact, and your side simply gave in
322 to that statement and gave up, while the other side tried to have a
323 more positive attitude. You can sometimes come up with a better
324 resolution by viewing the original.
325
327 After seeing a conflict, you can do two things:
328
329 · Decide not to merge. The only clean-ups you need are to reset the
330 index file to the HEAD commit to reverse 2. and to clean up working
331 tree changes made by 2. and 3.; git merge --abort can be used for
332 this.
333
334 · Resolve the conflicts. Git will mark the conflicts in the working
335 tree. Edit the files into shape and git add them to the index. Use
336 git commit to seal the deal.
337
338 You can work through the conflict with a number of tools:
339
340 · Use a mergetool. git mergetool to launch a graphical mergetool
341 which will work you through the merge.
342
343 · Look at the diffs. git diff will show a three-way diff,
344 highlighting changes from both the HEAD and MERGE_HEAD versions.
345
346 · Look at the diffs from each branch. git log --merge -p <path> will
347 show diffs first for the HEAD version and then the MERGE_HEAD
348 version.
349
350 · Look at the originals. git show :1:filename shows the common
351 ancestor, git show :2:filename shows the HEAD version, and git show
352 :3:filename shows the MERGE_HEAD version.
353
355 · Merge branches fixes and enhancements on top of the current branch,
356 making an octopus merge:
357
358 $ git merge fixes enhancements
359
360
361 · Merge branch obsolete into the current branch, using ours merge
362 strategy:
363
364 $ git merge -s ours obsolete
365
366
367 · Merge branch maint into the current branch, but do not make a new
368 commit automatically:
369
370 $ git merge --no-commit maint
371
372 This can be used when you want to include further changes to the
373 merge, or want to write your own merge commit message.
374
375 You should refrain from abusing this option to sneak substantial
376 changes into a merge commit. Small fixups like bumping
377 release/version name would be acceptable.
378
380 The merge mechanism (git-merge and git-pull commands) allows the
381 backend merge strategies to be chosen with -s option. Some strategies
382 can also take their own options, which can be passed by giving
383 -X<option> arguments to git-merge and/or git-pull.
384
385 resolve
386 This can only resolve two heads (i.e. the current branch and
387 another branch you pulled from) using a 3-way merge algorithm. It
388 tries to carefully detect criss-cross merge ambiguities and is
389 considered generally safe and fast.
390
391 recursive
392 This can only resolve two heads using a 3-way merge algorithm. When
393 there is more than one common ancestor that can be used for 3-way
394 merge, it creates a merged tree of the common ancestors and uses
395 that as the reference tree for the 3-way merge. This has been
396 reported to result in fewer merge conflicts without causing
397 mis-merges by tests done on actual merge commits taken from Linux
398 2.6 kernel development history. Additionally this can detect and
399 handle merges involving renames. This is the default merge strategy
400 when pulling or merging one branch.
401
402 The recursive strategy can take the following options:
403
404 ours
405 This option forces conflicting hunks to be auto-resolved
406 cleanly by favoring our version. Changes from the other tree
407 that do not conflict with our side are reflected to the merge
408 result. For a binary file, the entire contents are taken from
409 our side.
410
411 This should not be confused with the ours merge strategy, which
412 does not even look at what the other tree contains at all. It
413 discards everything the other tree did, declaring our history
414 contains all that happened in it.
415
416 theirs
417 This is the opposite of ours.
418
419 patience
420 With this option, merge-recursive spends a little extra time to
421 avoid mismerges that sometimes occur due to unimportant
422 matching lines (e.g., braces from distinct functions). Use this
423 when the branches to be merged have diverged wildly. See also
424 git-diff(1)--patience.
425
426 diff-algorithm=[patience|minimal|histogram|myers]
427 Tells merge-recursive to use a different diff algorithm, which
428 can help avoid mismerges that occur due to unimportant matching
429 lines (such as braces from distinct functions). See also git-
430 diff(1)--diff-algorithm.
431
432 ignore-space-change, ignore-all-space, ignore-space-at-eol
433 Treats lines with the indicated type of whitespace change as
434 unchanged for the sake of a three-way merge. Whitespace changes
435 mixed with other changes to a line are not ignored. See also
436 git-diff(1)-b, -w, and --ignore-space-at-eol.
437
438 · If their version only introduces whitespace changes to a
439 line, our version is used;
440
441 · If our version introduces whitespace changes but their
442 version includes a substantial change, their version is
443 used;
444
445 · Otherwise, the merge proceeds in the usual way.
446
447 renormalize
448 This runs a virtual check-out and check-in of all three stages
449 of a file when resolving a three-way merge. This option is
450 meant to be used when merging branches with different clean
451 filters or end-of-line normalization rules. See "Merging
452 branches with differing checkin/checkout attributes" in
453 gitattributes(5) for details.
454
455 no-renormalize
456 Disables the renormalize option. This overrides the
457 merge.renormalize configuration variable.
458
459 rename-threshold=<n>
460 Controls the similarity threshold used for rename detection.
461 See also git-diff(1)-M.
462
463 subtree[=<path>]
464 This option is a more advanced form of subtree strategy, where
465 the strategy makes a guess on how two trees must be shifted to
466 match with each other when merging. Instead, the specified path
467 is prefixed (or stripped from the beginning) to make the shape
468 of two trees to match.
469
470 octopus
471 This resolves cases with more than two heads, but refuses to do a
472 complex merge that needs manual resolution. It is primarily meant
473 to be used for bundling topic branch heads together. This is the
474 default merge strategy when pulling or merging more than one
475 branch.
476
477 ours
478 This resolves any number of heads, but the resulting tree of the
479 merge is always that of the current branch head, effectively
480 ignoring all changes from all other branches. It is meant to be
481 used to supersede old development history of side branches. Note
482 that this is different from the -Xours option to the recursive
483 merge strategy.
484
485 subtree
486 This is a modified recursive strategy. When merging trees A and B,
487 if B corresponds to a subtree of A, B is first adjusted to match
488 the tree structure of A, instead of reading the trees at the same
489 level. This adjustment is also done to the common ancestor tree.
490
492 merge.conflictstyle
493 Specify the style in which conflicted hunks are written out to
494 working tree files upon merge. The default is "merge", which shows
495 a <<<<<<< conflict marker, changes made by one side, a =======
496 marker, changes made by the other side, and then a >>>>>>> marker.
497 An alternate style, "diff3", adds a ||||||| marker and the original
498 text before the ======= marker.
499
500 merge.defaultToUpstream
501 If merge is called without any commit argument, merge the upstream
502 branches configured for the current branch by using their last
503 observed values stored in their remote-tracking branches. The
504 values of the branch.<current branch>.merge that name the branches
505 at the remote named by branch.<current branch>.remote are
506 consulted, and then they are mapped via remote.<remote>.fetch to
507 their corresponding remote-tracking branches, and the tips of these
508 tracking branches are merged.
509
510 merge.ff
511 By default, Git does not create an extra merge commit when merging
512 a commit that is a descendant of the current commit. Instead, the
513 tip of the current branch is fast-forwarded. When set to false,
514 this variable tells Git to create an extra merge commit in such a
515 case (equivalent to giving the --no-ff option from the command
516 line). When set to only, only such fast-forward merges are allowed
517 (equivalent to giving the --ff-only option from the command line).
518
519 merge.log
520 In addition to branch names, populate the log message with at most
521 the specified number of one-line descriptions from the actual
522 commits that are being merged. Defaults to false, and true is a
523 synonym for 20.
524
525 merge.renameLimit
526 The number of files to consider when performing rename detection
527 during a merge; if not specified, defaults to the value of
528 diff.renameLimit.
529
530 merge.renormalize
531 Tell Git that canonical representation of files in the repository
532 has changed over time (e.g. earlier commits record text files with
533 CRLF line endings, but recent ones use LF line endings). In such a
534 repository, Git can convert the data recorded in commits to a
535 canonical form before performing a merge to reduce unnecessary
536 conflicts. For more information, see section "Merging branches with
537 differing checkin/checkout attributes" in gitattributes(5).
538
539 merge.stat
540 Whether to print the diffstat between ORIG_HEAD and the merge
541 result at the end of the merge. True by default.
542
543 merge.tool
544 Controls which merge tool is used by git-mergetool(1). The list
545 below shows the valid built-in values. Any other value is treated
546 as a custom merge tool and requires that a corresponding
547 mergetool.<tool>.cmd variable is defined.
548
549 · araxis
550
551 · bc3
552
553 · codecompare
554
555 · deltawalker
556
557 · diffuse
558
559 · ecmerge
560
561 · emerge
562
563 · gvimdiff
564
565 · gvimdiff2
566
567 · kdiff3
568
569 · meld
570
571 · opendiff
572
573 · p4merge
574
575 · tkdiff
576
577 · tortoisemerge
578
579 · vimdiff
580
581 · vimdiff2
582
583 · xxdiff
584
585 merge.verbosity
586 Controls the amount of output shown by the recursive merge
587 strategy. Level 0 outputs nothing except a final error message if
588 conflicts were detected. Level 1 outputs only conflicts, 2 outputs
589 conflicts and file changes. Level 5 and above outputs debugging
590 information. The default is level 2. Can be overridden by the
591 GIT_MERGE_VERBOSITY environment variable.
592
593 merge.<driver>.name
594 Defines a human-readable name for a custom low-level merge driver.
595 See gitattributes(5) for details.
596
597 merge.<driver>.driver
598 Defines the command that implements a custom low-level merge
599 driver. See gitattributes(5) for details.
600
601 merge.<driver>.recursive
602 Names a low-level merge driver to be used when performing an
603 internal merge between common ancestors. See gitattributes(5) for
604 details.
605
606 branch.<name>.mergeoptions
607 Sets default options for merging into branch <name>. The syntax and
608 supported options are the same as those of git merge, but option
609 values containing whitespace characters are currently not
610 supported.
611
613 git-fmt-merge-msg(1), git-pull(1), gitattributes(5), git-reset(1), git-
614 diff(1), git-ls-files(1), git-add(1), git-rm(1), git-mergetool(1)
615
617 Part of the git(1) suite
618
619
620
621Git 1.8.3.1 11/19/2018 GIT-MERGE(1)