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