]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-merge.txt
push: make non-fast-forward help message configurable
[thirdparty/git.git] / Documentation / git-merge.txt
CommitLineData
0f69be53
JH
1git-merge(1)
2============
0f69be53
JH
3
4NAME
5----
c3f0baac 6git-merge - Join two or more development histories together
0f69be53
JH
7
8
9SYNOPSIS
10--------
17bcdad3 11[verse]
b1889c36 12'git merge' [-n] [--stat] [--no-commit] [--squash] [-s <strategy>]...
22f1fb66 13 [-m <msg>] <remote>...
b1889c36 14'git merge' <msg> HEAD <remote>...
0f69be53
JH
15
16DESCRIPTION
17-----------
17bcdad3 18This is the top-level interface to the merge machinery
0f69be53
JH
19which drives multiple merge strategy scripts.
20
dee48c3c
JH
21The second syntax (<msg> `HEAD` <remote>) is supported for
22historical reasons. Do not use it from the command line or in
23new scripts. It is the same as `git merge -m <msg> <remote>`.
24
0f69be53
JH
25
26OPTIONS
27-------
93d69d86 28include::merge-options.txt[]
0f69be53 29
dee48c3c 30-m <msg>::
3c64314c 31 The commit message to be used for the merge commit (in case
ba020ef5
JN
32 it is created). The 'git-fmt-merge-msg' script can be used
33 to give a good default for automated 'git-merge' invocations.
3c64314c 34
f448e24e
AMS
35<remote>...::
36 Other branch heads to merge into our branch. You need at
0f69be53
JH
37 least one <remote>. Specifying more than one <remote>
38 obviously means you are trying an Octopus.
39
bb73d73c
JL
40include::merge-strategies.txt[]
41
0f69be53 42
9fe00538 43If you tried a merge which resulted in complex conflicts and
4fa535a1 44want to start over, you can recover with 'git-reset'.
3ae854c3 45
dbddb714
JN
46CONFIGURATION
47-------------
f5a84c37 48include::merge-config.txt[]
dbddb714 49
aec7b362
LH
50branch.<name>.mergeoptions::
51 Sets default options for merging into branch <name>. The syntax and
ba020ef5 52 supported options are equal to that of 'git-merge', but option values
aec7b362 53 containing whitespace characters are currently not supported.
3ae854c3 54
ffb1a4be
JH
55HOW MERGE WORKS
56---------------
57
58A merge is always between the current `HEAD` and one or more
81646ad2 59commits (usually, branch head or tag), and the index file must
c0be8aa0
PB
60match the tree of `HEAD` commit (i.e. the contents of the last commit)
61when it starts out. In other words, `git diff --cached HEAD` must
62report no changes. (One exception is when the changed index
63entries are already in the same state that would result from
64the merge anyway.)
65
66Three kinds of merge can happen:
67
68* The merged commit is already contained in `HEAD`. This is the
69 simplest case, called "Already up-to-date."
70
71* `HEAD` is already contained in the merged commit. This is the
29b802aa
RW
72 most common case especially when invoked from 'git pull':
73 you are tracking an upstream repository, have committed no local
c0be8aa0 74 changes and now you want to update to a newer upstream revision.
29b802aa 75 Your `HEAD` (and the index) is updated to point at the merged
c0be8aa0
PB
76 commit, without creating an extra merge commit. This is
77 called "Fast-forward".
78
79* Both the merged commit and `HEAD` are independent and must be
29b802aa 80 tied together by a merge commit that has both of them as its parents.
c0be8aa0
PB
81 The rest of this section describes this "True merge" case.
82
83The chosen merge strategy merges the two commits into a single
84new source tree.
29b802aa 85When things merge cleanly, this is what happens:
ffb1a4be 86
434e6ef8
SH
871. The results are updated both in the index file and in your
88 working tree;
892. Index file is written out as a tree;
903. The tree gets committed; and
914. The `HEAD` pointer gets advanced.
ffb1a4be
JH
92
93Because of 2., we require that the original state of the index
29b802aa 94file matches exactly the current `HEAD` commit; otherwise we
ffb1a4be
JH
95will write out your local changes already registered in your
96index file along with the merge result, which is not good.
29b802aa 97Because 1. involves only those paths differing between your
ffb1a4be
JH
98branch and the remote branch you are pulling from during the
99merge (which is typically a fraction of the whole tree), you can
100have local modifications in your working tree as long as they do
101not overlap with what the merge updates.
102
29b802aa 103When there are conflicts, the following happens:
ffb1a4be
JH
104
1051. `HEAD` stays the same.
106
1072. Cleanly merged paths are updated both in the index file and
108 in your working tree.
109
3ace1fe3
JH
1103. For conflicting paths, the index file records up to three
111 versions; stage1 stores the version from the common ancestor,
112 stage2 from `HEAD`, and stage3 from the remote branch (you
b1889c36 113 can inspect the stages with `git ls-files -u`). The working
29b802aa
RW
114 tree files contain the result of the "merge" program; i.e. 3-way
115 merge results with familiar conflict markers `<<< === >>>`.
ffb1a4be
JH
116
1174. No other changes are done. In particular, the local
118 modifications you had before you started merge will stay the
119 same and the index entries for them stay as they were,
120 i.e. matching `HEAD`.
121
70a3f897
JH
122HOW CONFLICTS ARE PRESENTED
123---------------------------
124
125During a merge, the working tree files are updated to reflect the result
126of the merge. Among the changes made to the common ancestor's version,
127non-overlapping ones (that is, you changed an area of the file while the
128other side left that area intact, or vice versa) are incorporated in the
129final result verbatim. When both sides made changes to the same area,
130however, git cannot randomly pick one side over the other, and asks you to
131resolve it by leaving what both sides did to that area.
132
133By default, git uses the same style as that is used by "merge" program
134from the RCS suite to present such a conflicted hunk, like this:
135
136------------
137Here are lines that are either unchanged from the common
138ancestor, or cleanly resolved because only one side changed.
139<<<<<<< yours:sample.txt
140Conflict resolution is hard;
141let's go shopping.
142=======
143Git makes conflict resolution easy.
144>>>>>>> theirs:sample.txt
145And here is another line that is cleanly resolved or unmodified.
146------------
147
29b802aa 148The area where a pair of conflicting changes happened is marked with markers
dcb11263 149`<<<<<<<`, `=======`, and `>>>>>>>`. The part before the `=======`
29b802aa 150is typically your side, and the part afterwards is typically their side.
70a3f897 151
29b802aa
RW
152The default format does not show what the original said in the conflicting
153area. You cannot tell how many lines are deleted and replaced with
154Barbie's remark on your side. The only thing you can tell is that your
70a3f897
JH
155side wants to say it is hard and you'd prefer to go shopping, while the
156other side wants to claim it is easy.
157
158An alternative style can be used by setting the "merge.conflictstyle"
159configuration variable to "diff3". In "diff3" style, the above conflict
160may look like this:
161
162------------
163Here are lines that are either unchanged from the common
164ancestor, or cleanly resolved because only one side changed.
165<<<<<<< yours:sample.txt
166Conflict resolution is hard;
167let's go shopping.
168|||||||
169Conflict resolution is hard.
170=======
171Git makes conflict resolution easy.
172>>>>>>> theirs:sample.txt
173And here is another line that is cleanly resolved or unmodified.
174------------
175
dcb11263
CJ
176In addition to the `<<<<<<<`, `=======`, and `>>>>>>>` markers, it uses
177another `|||||||` marker that is followed by the original text. You can
70a3f897
JH
178tell that the original just stated a fact, and your side simply gave in to
179that statement and gave up, while the other side tried to have a more
180positive attitude. You can sometimes come up with a better resolution by
181viewing the original.
182
183
184HOW TO RESOLVE CONFLICTS
185------------------------
186
ffb1a4be
JH
187After seeing a conflict, you can do two things:
188
29b802aa 189 * Decide not to merge. The only clean-ups you need are to reset
ffb1a4be 190 the index file to the `HEAD` commit to reverse 2. and to clean
c0be8aa0 191 up working tree changes made by 2. and 3.; 'git-reset --hard' can
ffb1a4be
JH
192 be used for this.
193
34ad1afa
DH
194 * Resolve the conflicts. Git will mark the conflicts in
195 the working tree. Edit the files into shape and
29b802aa 196 'git-add' them to the index. Use 'git-commit' to seal the deal.
ffb1a4be 197
34ad1afa
DH
198You can work through the conflict with a number of tools:
199
200 * Use a mergetool. 'git mergetool' to launch a graphical
201 mergetool which will work you through the merge.
202
203 * Look at the diffs. 'git diff' will show a three-way diff,
204 highlighting changes from both the HEAD and remote versions.
205
206 * Look at the diffs on their own. 'git log --merge -p <path>'
207 will show diffs first for the HEAD version and then the
208 remote version.
209
210 * Look at the originals. 'git show :1:filename' shows the
211 common ancestor, 'git show :2:filename' shows the HEAD
212 version and 'git show :3:filename' shows the remote version.
ffb1a4be 213
3c64314c
PB
214SEE ALSO
215--------
5162e697 216linkgit:git-fmt-merge-msg[1], linkgit:git-pull[1],
483bc4f0
JN
217linkgit:gitattributes[5],
218linkgit:git-reset[1],
219linkgit:git-diff[1], linkgit:git-ls-files[1],
220linkgit:git-add[1], linkgit:git-rm[1],
221linkgit:git-mergetool[1]
3c64314c 222
0f69be53
JH
223Author
224------
59eb68aa 225Written by Junio C Hamano <gitster@pobox.com>
0f69be53
JH
226
227
228Documentation
229--------------
230Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
231
232GIT
233---
9e1f0a85 234Part of the linkgit:git[1] suite