1GIT-MERGE(1)                      Git Manual                      GIT-MERGE(1)
2
3
4

NAME

6       git-merge - Join two or more development histories together
7

SYNOPSIS

9       git merge [-n] [--stat] [--no-commit] [--squash]
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

DESCRIPTION

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

OPTIONS

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       --ff, --no-ff
67           Do not generate a merge commit if the merge resolved as a
68           fast-forward, only update the branch pointer. This is the default
69           behavior of git-merge.
70
71           With --no-ff Generate a merge commit even if the merge resolved as
72           a fast-forward.
73
74       --log[=<n>], --no-log
75           In addition to branch names, populate the log message with one-line
76           descriptions from at most <n> actual commits that are being merged.
77           See also git-fmt-merge-msg(1).
78
79           With --no-log do not list one-line descriptions from the actual
80           commits being merged.
81
82       --stat, -n, --no-stat
83           Show a diffstat at the end of the merge. The diffstat is also
84           controlled by the configuration option merge.stat.
85
86           With -n or --no-stat do not show a diffstat at the end of the
87           merge.
88
89       --squash, --no-squash
90           Produce the working tree and index state as if a real merge
91           happened (except for the merge information), but do not actually
92           make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to
93           cause the next git commit command to create a merge commit. This
94           allows you to create a single commit on top of the current branch
95           whose effect is the same as merging another branch (or more in case
96           of an octopus).
97
98           With --no-squash perform the merge and commit the result. This
99           option can be used to override --squash.
100
101       --ff-only
102           Refuse to merge and exit with a non-zero status unless the current
103           HEAD is already up-to-date or the merge can be resolved as a
104           fast-forward.
105
106       -s <strategy>, --strategy=<strategy>
107           Use the given merge strategy; can be supplied more than once to
108           specify them in the order they should be tried. If there is no -s
109           option, a built-in list of strategies is used instead (git
110           merge-recursive when merging a single head, git merge-octopus
111           otherwise).
112
113       -X <option>, --strategy-option=<option>
114           Pass merge strategy specific option through to the merge strategy.
115
116       --summary, --no-summary
117           Synonyms to --stat and --no-stat; these are deprecated and will be
118           removed in the future.
119
120       -q, --quiet
121           Operate quietly.
122
123       -v, --verbose
124           Be verbose.
125
126       -m <msg>
127           Set the commit message to be used for the merge commit (in case one
128           is created).
129
130           If --log is specified, a shortlog of the commits being merged will
131           be appended to the specified message.
132
133           The git fmt-merge-msg command can be used to give a good default
134           for automated git merge invocations.
135
136       --rerere-autoupdate, --no-rerere-autoupdate
137           Allow the rerere mechanism to update the index with the result of
138           auto-conflict resolution if possible.
139
140       --abort
141           Abort the current conflict resolution process, and try to
142           reconstruct the pre-merge state.
143
144           If there were uncommitted worktree changes present when the merge
145           started, git merge --abort will in some cases be unable to
146           reconstruct these changes. It is therefore recommended to always
147           commit or stash your changes before running git merge.
148
149           git merge --abort is equivalent to git reset --merge when
150           MERGE_HEAD is present.
151
152       <commit>...
153           Commits, usually other branch heads, to merge into our branch. You
154           need at least one <commit>. Specifying more than one <commit>
155           obviously means you are trying an Octopus.
156

PRE-MERGE CHECKS

158       Before applying outside changes, you should get your own work in good
159       shape and committed locally, so it will not be clobbered if there are
160       conflicts. See also git-stash(1). git pull and git merge will stop
161       without doing anything when local uncommitted changes overlap with
162       files that git pull/git merge may need to update.
163
164       To avoid recording unrelated changes in the merge commit, git pull and
165       git merge will also abort if there are any changes registered in the
166       index relative to the HEAD commit. (One exception is when the changed
167       index entries are in the state that would result from the merge
168       already.)
169
170       If all named commits are already ancestors of HEAD, git merge will exit
171       early with the message "Already up-to-date."
172

FAST-FORWARD MERGE

174       Often the current branch head is an ancestor of the named commit. This
175       is the most common case especially when invoked from git pull: you are
176       tracking an upstream repository, you have committed no local changes,
177       and now you want to update to a newer upstream revision. In this case,
178       a new commit is not needed to store the combined history; instead, the
179       HEAD (along with the index) is updated to point at the named commit,
180       without creating an extra merge commit.
181
182       This behavior can be suppressed with the --no-ff option.
183

TRUE MERGE

185       Except in a fast-forward merge (see above), the branches to be merged
186       must be tied together by a merge commit that has both of them as its
187       parents.
188
189       A merged version reconciling the changes from all branches to be merged
190       is committed, and your HEAD, index, and working tree are updated to it.
191       It is possible to have modifications in the working tree as long as
192       they do not overlap; the update will preserve them.
193
194       When it is not obvious how to reconcile the changes, the following
195       happens:
196
197        1. The HEAD pointer stays the same.
198
199        2. The MERGE_HEAD ref is set to point to the other branch head.
200
201        3. Paths that merged cleanly are updated both in the index file and in
202           your working tree.
203
204        4. For conflicting paths, the index file records up to three versions:
205           stage 1 stores the version from the common ancestor, stage 2 from
206           HEAD, and stage 3 from MERGE_HEAD (you can inspect the stages with
207           git ls-files -u). The working tree files contain the result of the
208           "merge" program; i.e. 3-way merge results with familiar conflict
209           markers <<< === >>>.
210
211        5. No other changes are made. In particular, the local modifications
212           you had before you started merge will stay the same and the index
213           entries for them stay as they were, i.e. matching HEAD.
214
215       If you tried a merge which resulted in complex conflicts and want to
216       start over, you can recover with git merge --abort.
217

HOW CONFLICTS ARE PRESENTED

219       During a merge, the working tree files are updated to reflect the
220       result of the merge. Among the changes made to the common ancestor’s
221       version, non-overlapping ones (that is, you changed an area of the file
222       while the other side left that area intact, or vice versa) are
223       incorporated in the final result verbatim. When both sides made changes
224       to the same area, however, git cannot randomly pick one side over the
225       other, and asks you to resolve it by leaving what both sides did to
226       that area.
227
228       By default, git uses the same style as that is used by "merge" program
229       from the RCS suite to present such a conflicted hunk, like this:
230
231           Here are lines that are either unchanged from the common
232           ancestor, or cleanly resolved because only one side changed.
233           <<<<<<< yours:sample.txt
234           Conflict resolution is hard;
235           let's go shopping.
236           =======
237           Git makes conflict resolution easy.
238           >>>>>>> theirs:sample.txt
239           And here is another line that is cleanly resolved or unmodified.
240
241
242       The area where a pair of conflicting changes happened is marked with
243       markers <<<<<<<, =======, and >>>>>>>. The part before the ======= is
244       typically your side, and the part afterwards is typically their side.
245
246       The default format does not show what the original said in the
247       conflicting area. You cannot tell how many lines are deleted and
248       replaced with Barbie’s remark on your side. The only thing you can tell
249       is that your side wants to say it is hard and you’d prefer to go
250       shopping, while the other side wants to claim it is easy.
251
252       An alternative style can be used by setting the "merge.conflictstyle"
253       configuration variable to "diff3". In "diff3" style, the above conflict
254       may look like this:
255
256           Here are lines that are either unchanged from the common
257           ancestor, or cleanly resolved because only one side changed.
258           <<<<<<< yours:sample.txt
259           Conflict resolution is hard;
260           let's go shopping.
261           |||||||
262           Conflict resolution is hard.
263           =======
264           Git makes conflict resolution easy.
265           >>>>>>> theirs:sample.txt
266           And here is another line that is cleanly resolved or unmodified.
267
268
269       In addition to the <<<<<<<, =======, and >>>>>>> markers, it uses
270       another ||||||| marker that is followed by the original text. You can
271       tell that the original just stated a fact, and your side simply gave in
272       to that statement and gave up, while the other side tried to have a
273       more positive attitude. You can sometimes come up with a better
274       resolution by viewing the original.
275

HOW TO RESOLVE CONFLICTS

277       After seeing a conflict, you can do two things:
278
279       ·   Decide not to merge. The only clean-ups you need are to reset the
280           index file to the HEAD commit to reverse 2. and to clean up working
281           tree changes made by 2. and 3.; git merge --abort can be used for
282           this.
283
284       ·   Resolve the conflicts. Git will mark the conflicts in the working
285           tree. Edit the files into shape and git add them to the index. Use
286           git commit to seal the deal.
287
288       You can work through the conflict with a number of tools:
289
290       ·   Use a mergetool.  git mergetool to launch a graphical mergetool
291           which will work you through the merge.
292
293       ·   Look at the diffs.  git diff will show a three-way diff,
294           highlighting changes from both the HEAD and MERGE_HEAD versions.
295
296       ·   Look at the diffs from each branch.  git log --merge -p <path> will
297           show diffs first for the HEAD version and then the MERGE_HEAD
298           version.
299
300       ·   Look at the originals.  git show :1:filename shows the common
301           ancestor, git show :2:filename shows the HEAD version, and git show
302           :3:filename shows the MERGE_HEAD version.
303

EXAMPLES

305       ·   Merge branches fixes and enhancements on top of the current branch,
306           making an octopus merge:
307
308               $ git merge fixes enhancements
309
310
311       ·   Merge branch obsolete into the current branch, using ours merge
312           strategy:
313
314               $ git merge -s ours obsolete
315
316
317       ·   Merge branch maint into the current branch, but do not make a new
318           commit automatically:
319
320               $ git merge --no-commit maint
321
322           This can be used when you want to include further changes to the
323           merge, or want to write your own merge commit message.
324
325           You should refrain from abusing this option to sneak substantial
326           changes into a merge commit. Small fixups like bumping
327           release/version name would be acceptable.
328

MERGE STRATEGIES

330       The merge mechanism (git-merge and git-pull commands) allows the
331       backend merge strategies to be chosen with -s option. Some strategies
332       can also take their own options, which can be passed by giving
333       -X<option> arguments to git-merge and/or git-pull.
334
335       resolve
336           This can only resolve two heads (i.e. the current branch and
337           another branch you pulled from) using a 3-way merge algorithm. It
338           tries to carefully detect criss-cross merge ambiguities and is
339           considered generally safe and fast.
340
341       recursive
342           This can only resolve two heads using a 3-way merge algorithm. When
343           there is more than one common ancestor that can be used for 3-way
344           merge, it creates a merged tree of the common ancestors and uses
345           that as the reference tree for the 3-way merge. This has been
346           reported to result in fewer merge conflicts without causing
347           mis-merges by tests done on actual merge commits taken from Linux
348           2.6 kernel development history. Additionally this can detect and
349           handle merges involving renames. This is the default merge strategy
350           when pulling or merging one branch.
351
352           The recursive strategy can take the following options:
353
354           ours
355               This option forces conflicting hunks to be auto-resolved
356               cleanly by favoring our version. Changes from the other tree
357               that do not conflict with our side are reflected to the merge
358               result.
359
360               This should not be confused with the ours merge strategy, which
361               does not even look at what the other tree contains at all. It
362               discards everything the other tree did, declaring our history
363               contains all that happened in it.
364
365           theirs
366               This is opposite of ours.
367
368           patience
369               With this option, merge-recursive spends a little extra time to
370               avoid mismerges that sometimes occur due to unimportant
371               matching lines (e.g., braces from distinct functions). Use this
372               when the branches to be merged have diverged wildly. See also
373               git-diff(1) --patience.
374
375           ignore-space-change, ignore-all-space, ignore-space-at-eol
376               Treats lines with the indicated type of whitespace change as
377               unchanged for the sake of a three-way merge. Whitespace changes
378               mixed with other changes to a line are not ignored. See also
379               git-diff(1) -b, -w, and --ignore-space-at-eol.
380
381               ·   If their version only introduces whitespace changes to a
382                   line, our version is used;
383
384               ·   If our version introduces whitespace changes but their
385                   version includes a substantial change, their version is
386                   used;
387
388               ·   Otherwise, the merge proceeds in the usual way.
389
390           renormalize
391               This runs a virtual check-out and check-in of all three stages
392               of a file when resolving a three-way merge. This option is
393               meant to be used when merging branches with different clean
394               filters or end-of-line normalization rules. See "Merging
395               branches with differing checkin/checkout attributes" in
396               gitattributes(5) for details.
397
398           no-renormalize
399               Disables the renormalize option. This overrides the
400               merge.renormalize configuration variable.
401
402           rename-threshold=<n>
403               Controls the similarity threshold used for rename detection.
404               See also git-diff(1) -M.
405
406           subtree[=<path>]
407               This option is a more advanced form of subtree strategy, where
408               the strategy makes a guess on how two trees must be shifted to
409               match with each other when merging. Instead, the specified path
410               is prefixed (or stripped from the beginning) to make the shape
411               of two trees to match.
412
413       octopus
414           This resolves cases with more than two heads, but refuses to do a
415           complex merge that needs manual resolution. It is primarily meant
416           to be used for bundling topic branch heads together. This is the
417           default merge strategy when pulling or merging more than one
418           branch.
419
420       ours
421           This resolves any number of heads, but the resulting tree of the
422           merge is always that of the current branch head, effectively
423           ignoring all changes from all other branches. It is meant to be
424           used to supersede old development history of side branches. Note
425           that this is different from the -Xours option to the recursive
426           merge strategy.
427
428       subtree
429           This is a modified recursive strategy. When merging trees A and B,
430           if B corresponds to a subtree of A, B is first adjusted to match
431           the tree structure of A, instead of reading the trees at the same
432           level. This adjustment is also done to the common ancestor tree.
433

CONFIGURATION

435       merge.conflictstyle
436           Specify the style in which conflicted hunks are written out to
437           working tree files upon merge. The default is "merge", which shows
438           a <<<<<<< conflict marker, changes made by one side, a =======
439           marker, changes made by the other side, and then a >>>>>>> marker.
440           An alternate style, "diff3", adds a ||||||| marker and the original
441           text before the ======= marker.
442
443       merge.log
444           In addition to branch names, populate the log message with at most
445           the specified number of one-line descriptions from the actual
446           commits that are being merged. Defaults to false, and true is a
447           synonym for 20.
448
449       merge.renameLimit
450           The number of files to consider when performing rename detection
451           during a merge; if not specified, defaults to the value of
452           diff.renameLimit.
453
454       merge.renormalize
455           Tell git that canonical representation of files in the repository
456           has changed over time (e.g. earlier commits record text files with
457           CRLF line endings, but recent ones use LF line endings). In such a
458           repository, git can convert the data recorded in commits to a
459           canonical form before performing a merge to reduce unnecessary
460           conflicts. For more information, see section "Merging branches with
461           differing checkin/checkout attributes" in gitattributes(5).
462
463       merge.stat
464           Whether to print the diffstat between ORIG_HEAD and the merge
465           result at the end of the merge. True by default.
466
467       merge.tool
468           Controls which merge resolution program is used by git-
469           mergetool(1). Valid built-in values are: "kdiff3", "tkdiff",
470           "meld", "xxdiff", "emerge", "vimdiff", "gvimdiff", "diffuse",
471           "ecmerge", "tortoisemerge", "p4merge", "araxis" and "opendiff". Any
472           other value is treated is custom merge tool and there must be a
473           corresponding mergetool.<tool>.cmd option.
474
475       merge.verbosity
476           Controls the amount of output shown by the recursive merge
477           strategy. Level 0 outputs nothing except a final error message if
478           conflicts were detected. Level 1 outputs only conflicts, 2 outputs
479           conflicts and file changes. Level 5 and above outputs debugging
480           information. The default is level 2. Can be overridden by the
481           GIT_MERGE_VERBOSITY environment variable.
482
483       merge.<driver>.name
484           Defines a human-readable name for a custom low-level merge driver.
485           See gitattributes(5) for details.
486
487       merge.<driver>.driver
488           Defines the command that implements a custom low-level merge
489           driver. See gitattributes(5) for details.
490
491       merge.<driver>.recursive
492           Names a low-level merge driver to be used when performing an
493           internal merge between common ancestors. See gitattributes(5) for
494           details.
495
496       branch.<name>.mergeoptions
497           Sets default options for merging into branch <name>. The syntax and
498           supported options are the same as those of git merge, but option
499           values containing whitespace characters are currently not
500           supported.
501

SEE ALSO

503       git-fmt-merge-msg(1), git-pull(1), gitattributes(5), git-reset(1), git-
504       diff(1), git-ls-files(1), git-add(1), git-rm(1), git-mergetool(1)
505

AUTHOR

507       Written by Junio C Hamano <gitster@pobox.com[1]>
508

DOCUMENTATION

510       Documentation by Junio C Hamano and the git-list
511       <git@vger.kernel.org[2]>.
512

GIT

514       Part of the git(1) suite
515

NOTES

517        1. gitster@pobox.com
518           mailto:gitster@pobox.com
519
520        2. git@vger.kernel.org
521           mailto:git@vger.kernel.org
522
523
524
525Git 1.7.4.4                       04/11/2011                      GIT-MERGE(1)
Impressum