send-email: add transfer encoding header with content-type
[git/dscho.git] / Documentation / git-merge.txt
blob827838f7d05e21875c9843fd782c4ade1a8b141e
1 git-merge(1)
2 ============
4 NAME
5 ----
6 git-merge - Join two or more development histories together
9 SYNOPSIS
10 --------
11 [verse]
12 'git-merge' [-n] [--summary] [--no-commit] [--squash] [-s <strategy>]...
13         [-m <msg>] <remote> <remote>...
14 'git-merge' <msg> HEAD <remote>...
16 DESCRIPTION
17 -----------
18 This is the top-level interface to the merge machinery
19 which drives multiple merge strategy scripts.
21 The second syntax (<msg> `HEAD` <remote>) is supported for
22 historical reasons.  Do not use it from the command line or in
23 new scripts.  It is the same as `git merge -m <msg> <remote>`.
26 OPTIONS
27 -------
28 include::merge-options.txt[]
30 -m <msg>::
31         The commit message to be used for the merge commit (in case
32         it is created). The `git-fmt-merge-msg` script can be used
33         to give a good default for automated `git-merge` invocations.
35 <remote>::
36         Other branch head merged into our branch.  You need at
37         least one <remote>.  Specifying more than one <remote>
38         obviously means you are trying an Octopus.
40 include::merge-strategies.txt[]
43 If you tried a merge which resulted in a complex conflicts and
44 would want to start over, you can recover with
45 gitlink:git-reset[1].
47 CONFIGURATION
48 -------------
50 merge.summary::
51         Whether to include summaries of merged commits in newly
52         created merge commit. False by default.
54 merge.verbosity::
55         Controls the amount of output shown by the recursive merge
56         strategy.  Level 0 outputs nothing except a final error
57         message if conflicts were detected. Level 1 outputs only
58         conflicts, 2 outputs conflicts and file changes.  Level 5 and
59         above outputs debugging information.  The default is level 2.
60         Can be overridden by 'GIT_MERGE_VERBOSITY' environment variable.
63 HOW MERGE WORKS
64 ---------------
66 A merge is always between the current `HEAD` and one or more
67 remote branch heads, and the index file must exactly match the
68 tree of `HEAD` commit (i.e. the contents of the last commit) when
69 it happens.  In other words, `git-diff --cached HEAD` must
70 report no changes.
72 [NOTE]
73 This is a bit of lie.  In certain special cases, your index are
74 allowed to be different from the tree of `HEAD` commit.  The most
75 notable case is when your `HEAD` commit is already ahead of what
76 is being merged, in which case your index can have arbitrary
77 difference from your `HEAD` commit.  Otherwise, your index entries
78 are allowed have differences from your `HEAD` commit that match
79 the result of trivial merge (e.g. you received the same patch
80 from external source to produce the same result as what you are
81 merging).  For example, if a path did not exist in the common
82 ancestor and your head commit but exists in the tree you are
83 merging into your repository, and if you already happen to have
84 that path exactly in your index, the merge does not have to
85 fail.
87 Otherwise, merge will refuse to do any harm to your repository
88 (that is, it may fetch the objects from remote, and it may even
89 update the local branch used to keep track of the remote branch
90 with `git pull remote rbranch:lbranch`, but your working tree,
91 `.git/HEAD` pointer and index file are left intact).
93 You may have local modifications in the working tree files.  In
94 other words, `git-diff` is allowed to report changes.
95 However, the merge uses your working tree as the working area,
96 and in order to prevent the merge operation from losing such
97 changes, it makes sure that they do not interfere with the
98 merge. Those complex tables in read-tree documentation define
99 what it means for a path to "interfere with the merge".  And if
100 your local modifications interfere with the merge, again, it
101 stops before touching anything.
103 So in the above two "failed merge" case, you do not have to
104 worry about loss of data --- you simply were not ready to do
105 a merge, so no merge happened at all.  You may want to finish
106 whatever you were in the middle of doing, and retry the same
107 pull after you are done and ready.
109 When things cleanly merge, these things happen:
111 1. The results are updated both in the index file and in your
112    working tree;
113 2. Index file is written out as a tree;
114 3. The tree gets committed; and
115 4. The `HEAD` pointer gets advanced.
117 Because of 2., we require that the original state of the index
118 file to match exactly the current `HEAD` commit; otherwise we
119 will write out your local changes already registered in your
120 index file along with the merge result, which is not good.
121 Because 1. involves only the paths different between your
122 branch and the remote branch you are pulling from during the
123 merge (which is typically a fraction of the whole tree), you can
124 have local modifications in your working tree as long as they do
125 not overlap with what the merge updates.
127 When there are conflicts, these things happen:
129 1. `HEAD` stays the same.
131 2. Cleanly merged paths are updated both in the index file and
132    in your working tree.
134 3. For conflicting paths, the index file records up to three
135    versions; stage1 stores the version from the common ancestor,
136    stage2 from `HEAD`, and stage3 from the remote branch (you
137    can inspect the stages with `git-ls-files -u`).  The working
138    tree files have the result of "merge" program; i.e. 3-way
139    merge result with familiar conflict markers `<<< === >>>`.
141 4. No other changes are done.  In particular, the local
142    modifications you had before you started merge will stay the
143    same and the index entries for them stay as they were,
144    i.e. matching `HEAD`.
146 After seeing a conflict, you can do two things:
148  * Decide not to merge.  The only clean-up you need are to reset
149    the index file to the `HEAD` commit to reverse 2. and to clean
150    up working tree changes made by 2. and 3.; `git-reset` can
151    be used for this.
153  * Resolve the conflicts.  `git-diff` would report only the
154    conflicting paths because of the above 2. and 3..  Edit the
155    working tree files into a desirable shape, `git-add` or `git-rm`
156    them, to make the index file contain what the merge result
157    should be, and run `git-commit` to commit the result.
160 SEE ALSO
161 --------
162 gitlink:git-fmt-merge-msg[1], gitlink:git-pull[1]
165 Author
166 ------
167 Written by Junio C Hamano <junkio@cox.net>
170 Documentation
171 --------------
172 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
176 Part of the gitlink:git[7] suite