Skip to content

Commit ebef7e5

Browse files
jrntrast
authored andcommitted
Documentation: simplify How Merge Works
The user most likely does not care about the exact order of operations because he cannot see it happening anyway. Instead, try to explain what it means to merge two commits into a single tree. While at it: - Change the heading to TRUE MERGE. The entire manual page is about how merges work. - Document MERGE_HEAD. It is a useful feature, since it makes the parents of the intended merge commit easier to refer to. - Do not assume commits named on the 'git merge' command line come from another repository. For simplicity, the discussion of conflicts still does assume that there is only one and it is a branch head. - Do not start list items with `code`. Otherwise, a toolchain bug produces a line break in the generated nroff, resulting in odd extra space. Suggested-by: Thomas Rast <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Thomas Rast <[email protected]>
1 parent 2928031 commit ebef7e5

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

Documentation/git-merge.txt

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,32 @@ merge commit.
100100

101101
This behavior can be suppressed with the `--no-ff` option.
102102

103-
HOW MERGE WORKS
104-
---------------
105-
106-
A merge is always between the current `HEAD` and one or more
107-
commits (usually a branch head or tag).
103+
TRUE MERGE
104+
----------
108105

109106
Except in a fast-forward merge (see above), the branches to be
110107
merged must be tied together by a merge commit that has both of them
111108
as its parents.
112-
The rest of this section describes this "True merge" case.
113-
114-
The chosen merge strategy merges the two commits into a single
115-
new source tree.
116-
When things merge cleanly, this is what happens:
117-
118-
1. The results are updated both in the index file and in your
119-
working tree;
120-
2. Index file is written out as a tree;
121-
3. The tree gets committed; and
122-
4. The `HEAD` pointer gets advanced.
123109

124-
Because of 2., we require that the original state of the index
125-
file matches exactly the current `HEAD` commit; otherwise we
126-
will write out your local changes already registered in your
127-
index file along with the merge result, which is not good.
128-
Because 1. involves only those paths differing between your
129-
branch and the branch you are merging
130-
(which is typically a fraction of the whole tree), you can
131-
have local modifications in your working tree as long as they do
132-
not overlap with what the merge updates.
110+
A merged version reconciling the changes from all branches to be
111+
merged is committed, and your `HEAD`, index, and working tree are
112+
updated to it. It is possible to have modifications in the working
113+
tree as long as they do not overlap; the update will preserve them.
133114

134-
When there are conflicts, the following happens:
115+
When it is not obvious how to reconcile the changes, the following
116+
happens:
135117

136-
1. `HEAD` stays the same.
137-
138-
2. Cleanly merged paths are updated both in the index file and
118+
1. The `HEAD` pointer stays the same.
119+
2. The `MERGE_HEAD` ref is set to point to the other branch head.
120+
3. Paths that merged cleanly are updated both in the index file and
139121
in your working tree.
140-
141-
3. For conflicting paths, the index file records up to three
142-
versions; stage1 stores the version from the common ancestor,
143-
stage2 from `HEAD`, and stage3 from the other branch (you
122+
4. For conflicting paths, the index file records up to three
123+
versions: stage 1 stores the version from the common ancestor,
124+
stage 2 from `HEAD`, and stage 3 from `MERGE_HEAD` (you
144125
can inspect the stages with `git ls-files -u`). The working
145126
tree files contain the result of the "merge" program; i.e. 3-way
146-
merge results with familiar conflict markers `<<< === >>>`.
147-
148-
4. No other changes are done. In particular, the local
127+
merge results with familiar conflict markers `<<<` `===` `>>>`.
128+
5. No other changes are made. In particular, the local
149129
modifications you had before you started merge will stay the
150130
same and the index entries for them stay as they were,
151131
i.e. matching `HEAD`.

0 commit comments

Comments
 (0)