merge-tree: remove unnecessary call of git_extract_argv0_path
[git/dscho.git] / Documentation / git-merge.txt
blobd4ef0d0ce2a3c75f964465e25106f9ab3ac53d89
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] [--stat] [--no-commit] [--squash] [-s <strategy>]...
13         [--[no-]rerere-autoupdate] [-m <msg>] <commit>...
14 'git merge' <msg> HEAD <commit>...
16 DESCRIPTION
17 -----------
18 Merges the history specified by <commit> into HEAD, optionally using a
19 specific merge strategy.
21 The second syntax (<msg> `HEAD` <commit>...) 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> <commit>...`.
25 *Warning*: Running 'git merge' with uncommitted changes is
26 discouraged: while possible, it leaves you in a state that is hard to
27 back out of in the case of a conflict.
30 OPTIONS
31 -------
32 include::merge-options.txt[]
34 -m <msg>::
35         Set the commit message to be used for the merge commit (in
36         case one is created). The 'git fmt-merge-msg' command can be
37         used to give a good default for automated 'git merge'
38         invocations.
40 --rerere-autoupdate::
41 --no-rerere-autoupdate::
42         Allow the rerere mechanism to update the index with the
43         result of auto-conflict resolution if possible.
45 <commit>...::
46         Commits, usually other branch heads, to merge into our branch.
47         You need at least one <commit>.  Specifying more than one
48         <commit> obviously means you are trying an Octopus.
50 include::merge-strategies.txt[]
53 If you tried a merge which resulted in complex conflicts and
54 want to start over, you can recover with 'git reset'.
56 CONFIGURATION
57 -------------
58 include::merge-config.txt[]
60 branch.<name>.mergeoptions::
61         Sets default options for merging into branch <name>. The syntax and
62         supported options are the same as those of 'git merge', but option
63         values containing whitespace characters are currently not supported.
65 HOW MERGE WORKS
66 ---------------
68 A merge is always between the current `HEAD` and one or more
69 commits (usually, branch head or tag), and the index file must
70 match the tree of `HEAD` commit (i.e. the contents of the last commit)
71 when it starts out.  In other words, `git diff --cached HEAD` must
72 report no changes.  (One exception is when the changed index
73 entries are already in the same state that would result from
74 the merge anyway.)
76 Three kinds of merge can happen:
78 * The merged commit is already contained in `HEAD`. This is the
79   simplest case, called "Already up-to-date."
81 * `HEAD` is already contained in the merged commit. This is the
82   most common case especially when invoked from 'git pull':
83   you are tracking an upstream repository, have committed no local
84   changes and now you want to update to a newer upstream revision.
85   Your `HEAD` (and the index) is updated to point at the merged
86   commit, without creating an extra merge commit.  This is
87   called "Fast-forward".
89 * Both the merged commit and `HEAD` are independent and must be
90   tied together by a merge commit that has both of them as its parents.
91   The rest of this section describes this "True merge" case.
93 The chosen merge strategy merges the two commits into a single
94 new source tree.
95 When things merge cleanly, this is what happens:
97 1. The results are updated both in the index file and in your
98    working tree;
99 2. Index file is written out as a tree;
100 3. The tree gets committed; and
101 4. The `HEAD` pointer gets advanced.
103 Because of 2., we require that the original state of the index
104 file matches exactly the current `HEAD` commit; otherwise we
105 will write out your local changes already registered in your
106 index file along with the merge result, which is not good.
107 Because 1. involves only those paths differing between your
108 branch and the branch you are merging
109 (which is typically a fraction of the whole tree), you can
110 have local modifications in your working tree as long as they do
111 not overlap with what the merge updates.
113 When there are conflicts, the following happens:
115 1. `HEAD` stays the same.
117 2. Cleanly merged paths are updated both in the index file and
118    in your working tree.
120 3. For conflicting paths, the index file records up to three
121    versions; stage1 stores the version from the common ancestor,
122    stage2 from `HEAD`, and stage3 from the other branch (you
123    can inspect the stages with `git ls-files -u`).  The working
124    tree files contain the result of the "merge" program; i.e. 3-way
125    merge results with familiar conflict markers `<<< === >>>`.
127 4. No other changes are done.  In particular, the local
128    modifications you had before you started merge will stay the
129    same and the index entries for them stay as they were,
130    i.e. matching `HEAD`.
132 HOW CONFLICTS ARE PRESENTED
133 ---------------------------
135 During a merge, the working tree files are updated to reflect the result
136 of the merge.  Among the changes made to the common ancestor's version,
137 non-overlapping ones (that is, you changed an area of the file while the
138 other side left that area intact, or vice versa) are incorporated in the
139 final result verbatim.  When both sides made changes to the same area,
140 however, git cannot randomly pick one side over the other, and asks you to
141 resolve it by leaving what both sides did to that area.
143 By default, git uses the same style as that is used by "merge" program
144 from the RCS suite to present such a conflicted hunk, like this:
146 ------------
147 Here are lines that are either unchanged from the common
148 ancestor, or cleanly resolved because only one side changed.
149 <<<<<<< yours:sample.txt
150 Conflict resolution is hard;
151 let's go shopping.
152 =======
153 Git makes conflict resolution easy.
154 >>>>>>> theirs:sample.txt
155 And here is another line that is cleanly resolved or unmodified.
156 ------------
158 The area where a pair of conflicting changes happened is marked with markers
159 `<<<<<<<`, `=======`, and `>>>>>>>`.  The part before the `=======`
160 is typically your side, and the part afterwards is typically their side.
162 The default format does not show what the original said in the conflicting
163 area.  You cannot tell how many lines are deleted and replaced with
164 Barbie's remark on your side.  The only thing you can tell is that your
165 side wants to say it is hard and you'd prefer to go shopping, while the
166 other side wants to claim it is easy.
168 An alternative style can be used by setting the "merge.conflictstyle"
169 configuration variable to "diff3".  In "diff3" style, the above conflict
170 may look like this:
172 ------------
173 Here are lines that are either unchanged from the common
174 ancestor, or cleanly resolved because only one side changed.
175 <<<<<<< yours:sample.txt
176 Conflict resolution is hard;
177 let's go shopping.
178 |||||||
179 Conflict resolution is hard.
180 =======
181 Git makes conflict resolution easy.
182 >>>>>>> theirs:sample.txt
183 And here is another line that is cleanly resolved or unmodified.
184 ------------
186 In addition to the `<<<<<<<`, `=======`, and `>>>>>>>` markers, it uses
187 another `|||||||` marker that is followed by the original text.  You can
188 tell that the original just stated a fact, and your side simply gave in to
189 that statement and gave up, while the other side tried to have a more
190 positive attitude.  You can sometimes come up with a better resolution by
191 viewing the original.
194 HOW TO RESOLVE CONFLICTS
195 ------------------------
197 After seeing a conflict, you can do two things:
199  * Decide not to merge.  The only clean-ups you need are to reset
200    the index file to the `HEAD` commit to reverse 2. and to clean
201    up working tree changes made by 2. and 3.; `git-reset --hard` can
202    be used for this.
204  * Resolve the conflicts.  Git will mark the conflicts in
205    the working tree.  Edit the files into shape and
206    'git add' them to the index.  Use 'git commit' to seal the deal.
208 You can work through the conflict with a number of tools:
210  * Use a mergetool.  `git mergetool` to launch a graphical
211    mergetool which will work you through the merge.
213  * Look at the diffs.  `git diff` will show a three-way diff,
214    highlighting changes from both the HEAD and their versions.
216  * Look at the diffs on their own. `git log --merge -p <path>`
217    will show diffs first for the HEAD version and then
218    their version.
220  * Look at the originals.  `git show :1:filename` shows the
221    common ancestor, `git show :2:filename` shows the HEAD
222    version and `git show :3:filename` shows their version.
225 EXAMPLES
226 --------
228 * Merge branches `fixes` and `enhancements` on top of
229   the current branch, making an octopus merge:
231 ------------------------------------------------
232 $ git merge fixes enhancements
233 ------------------------------------------------
235 * Merge branch `obsolete` into the current branch, using `ours`
236   merge strategy:
238 ------------------------------------------------
239 $ git merge -s ours obsolete
240 ------------------------------------------------
242 * Merge branch `maint` into the current branch, but do not make
243   a new commit automatically:
245 ------------------------------------------------
246 $ git merge --no-commit maint
247 ------------------------------------------------
249 This can be used when you want to include further changes to the
250 merge, or want to write your own merge commit message.
252 You should refrain from abusing this option to sneak substantial
253 changes into a merge commit.  Small fixups like bumping
254 release/version name would be acceptable.
257 SEE ALSO
258 --------
259 linkgit:git-fmt-merge-msg[1], linkgit:git-pull[1],
260 linkgit:gitattributes[5],
261 linkgit:git-reset[1],
262 linkgit:git-diff[1], linkgit:git-ls-files[1],
263 linkgit:git-add[1], linkgit:git-rm[1],
264 linkgit:git-mergetool[1]
266 Author
267 ------
268 Written by Junio C Hamano <gitster@pobox.com>
271 Documentation
272 --------------
273 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
277 Part of the linkgit:git[1] suite