interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-merge.adoc

293 lines · 10486 bytes Raw Blame History
1git-merge(1)
2============
3
4NAME
5----
6git-merge - Join two or more development histories together
7
8
9SYNOPSIS
10--------
11[synopsis]
12git merge [-n] [--stat] [--compact-summary] [--no-commit] [--squash] [--[no-]edit]
13 [--no-verify] [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
14 [--[no-]allow-unrelated-histories]
15 [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>]
16 [--into-name <branch>] [<commit>...]
17git merge (--continue | --abort | --quit)
18
19DESCRIPTION
20-----------
21Incorporates changes from the named commits (since the time their
22histories diverged from the current branch) into the current
23branch. This command is used by `git pull` to incorporate changes
24from another repository and can be used by hand to merge changes
25from one branch into another.
26
27Assume the following history exists and the current branch is
28`master`:
29
30------------
31 A---B---C topic
32 /
33 D---E---F---G master
34------------
35
36Then `git merge topic` will replay the changes made on the
37`topic` branch since it diverged from `master` (i.e., `E`) until
38its current commit (`C`) on top of `master`, and record the result
39in a new commit along with the names of the two parent commits and
40a log message from the user describing the changes. Before the operation,
41`ORIG_HEAD` is set to the tip of the current branch (`G`).
42
43------------
44 A---B---C topic
45 / \
46 D---E---F---G---H master
47------------
48
49A merge stops if there's a conflict that cannot be resolved
50automatically or if `--no-commit` was provided when initiating the
51merge. At that point you can run `git merge --abort` or `git merge
52--continue`. See linkgit:gitmergeconflicts[7]
53(or `git help mergeconflicts`) for a guide to handling merge conflicts.
54
55`git merge --abort` will abort the merge process and try to reconstruct
56the pre-merge state. However, if there were uncommitted changes when the
57merge started (and especially if those changes were further modified
58after the merge was started), `git merge --abort` will in some cases be
59unable to reconstruct the original (pre-merge) changes. Therefore:
60
61WARNING: Running `git merge` with non-trivial uncommitted changes is
62discouraged: while possible, it may leave you in a state that is hard to
63back out of in the case of a conflict.
64
65OPTIONS
66-------
67:git-merge: 1
68
69include::merge-options.adoc[]
70
71`-m <msg>`::
72 Set the commit message to be used for the merge commit (in
73 case one is created).
74+
75If `--log` is specified, a shortlog of the commits being merged
76will be appended to the specified message.
77+
78The `git fmt-merge-msg` command can be
79used to give a good default for automated `git merge`
80invocations. The automated message can include the branch description.
81
82`--into-name <branch>`::
83 Prepare the default merge message as if merging to the branch
84 _<branch>_, instead of the name of the real branch to which
85 the merge is made.
86
87`-F <file>`::
88`--file=<file>`::
89 Read the commit message to be used for the merge commit (in
90 case one is created).
91+
92If `--log` is specified, a shortlog of the commits being merged
93will be appended to the specified message.
94
95include::rerere-options.adoc[]
96
97`--overwrite-ignore`::
98`--no-overwrite-ignore`::
99 Silently overwrite ignored files from the merge result. This
100 is the default behavior. Use `--no-overwrite-ignore` to abort.
101
102`--abort`::
103 Abort the current conflict resolution process, and
104 try to reconstruct the pre-merge state. If an autostash entry is
105 present, apply it to the worktree.
106+
107If there were uncommitted worktree changes present when the merge
108started, `git merge --abort` will in some cases be unable to
109reconstruct these changes. It is therefore recommended to always
110commit or stash your changes before running `git merge`.
111+
112`git merge --abort` is equivalent to `git reset --merge` when
113`MERGE_HEAD` is present unless `MERGE_AUTOSTASH` is also present in
114which case `git merge --abort` applies the stash entry to the worktree
115whereas `git reset --merge` will save the stashed changes in the stash
116list.
117
118`--quit`::
119 Forget about the current merge in progress. Leave the index
120 and the working tree as-is. If `MERGE_AUTOSTASH` is present, the
121 stash entry will be saved to the stash list.
122
123`--continue`::
124 After a `git merge` stops due to conflicts you can conclude the
125 merge by running `git merge --continue` (see "HOW TO RESOLVE
126 CONFLICTS" section below).
127
128`<commit>...`::
129 Commits, usually other branch heads, to merge into our branch.
130 Specifying more than one commit will create a merge with
131 more than two parents (affectionately called an Octopus merge).
132+
133If no commit is given from the command line, merge the remote-tracking
134branches that the current branch is configured to use as its upstream.
135See also the configuration section of this manual page.
136+
137When `FETCH_HEAD` (and no other commit) is specified, the branches
138recorded in the `.git/FETCH_HEAD` file by the previous invocation
139of `git fetch` for merging are merged to the current branch.
140
141
142PRE-MERGE CHECKS
143----------------
144
145Before applying outside changes, you should get your own work in
146good shape and committed locally, so it will not be clobbered if
147there are conflicts. See also linkgit:git-stash[1].
148`git pull` and `git merge` will stop without doing anything when
149local uncommitted changes overlap with files that `git pull`/`git
150merge` may need to update.
151
152To avoid recording unrelated changes in the merge commit,
153`git pull` and `git merge` will also abort if there are any changes
154registered in the index relative to the `HEAD` commit. (Special
155narrow exceptions to this rule may exist depending on which merge
156strategy is in use, but generally, the index must match `HEAD`.)
157
158If all named commits are already ancestors of `HEAD`, `git merge`
159will exit early with the message "Already up to date."
160
161FAST-FORWARD MERGE
162------------------
163
164Often the current branch head is an ancestor of the named commit.
165This is the most common case especially when invoked from `git
166pull`: you are tracking an upstream repository, you have committed
167no local changes, and now you want to update to a newer upstream
168revision. In this case, a new commit is not needed to store the
169combined history; instead, the `HEAD` (along with the index) is
170updated to point at the named commit, without creating an extra
171merge commit.
172
173This behavior can be suppressed with the `--no-ff` option.
174
175TRUE MERGE
176----------
177
178Except in a fast-forward merge (see above), the branches to be
179merged must be tied together by a merge commit that has both of them
180as its parents.
181
182A merged version reconciling the changes from all branches to be
183merged is committed, and your `HEAD`, index, and working tree are
184updated to it. It is possible to have modifications in the working
185tree as long as they do not overlap; the update will preserve them.
186
187When it is not obvious how to reconcile the changes, the following
188happens:
189
1901. The `HEAD` pointer stays the same.
1912. The `MERGE_HEAD` ref is set to point to the other branch head.
1923. Paths that merged cleanly are updated both in the index file and
193 in your working tree.
1944. For conflicting paths, the index file records up to three
195 versions: stage 1 stores the version from the common ancestor,
196 stage 2 from `HEAD`, and stage 3 from `MERGE_HEAD` (you
197 can inspect the stages with `git ls-files -u`). The working
198 tree files contain the result of the merge operation; i.e. 3-way
199 merge results with familiar conflict markers +<<<+ `===` +>>>+.
2005. A ref named `AUTO_MERGE` is written, pointing to a tree
201 corresponding to the current content of the working tree (including
202 conflict markers for textual conflicts). Note that this ref is only
203 written when the `ort` merge strategy is used (the default).
2046. No other changes are made. In particular, the local
205 modifications you had before you started merge will stay the
206 same and the index entries for them stay as they were,
207 i.e. matching `HEAD`.
208
209If you tried a merge which resulted in complex conflicts and
210want to start over, you can recover with `git merge --abort`.
211
212MERGING TAG
213-----------
214
215When merging an annotated (and possibly signed) tag, Git always
216creates a merge commit even if a fast-forward merge is possible, and
217the commit message template is prepared with the tag message.
218Additionally, if the tag is signed, the signature check is reported
219as a comment in the message template. See also linkgit:git-tag[1].
220
221When you want to just integrate with the work leading to the commit
222that happens to be tagged, e.g. synchronizing with an upstream
223release point, you may not want to make an unnecessary merge commit.
224
225In such a case, you can "unwrap" the tag yourself before feeding it
226to `git merge`, or pass `--ff-only` when you do not have any work on
227your own. e.g.
228
229----
230git fetch origin
231git merge v1.2.3^0
232git merge --ff-only v1.2.3
233----
234
235EXAMPLES
236--------
237
238* Merge branches `fixes` and `enhancements` on top of
239 the current branch, making an octopus merge:
240+
241------------------------------------------------
242$ git merge fixes enhancements
243------------------------------------------------
244
245* Merge branch `obsolete` into the current branch, using `ours`
246 merge strategy:
247+
248------------------------------------------------
249$ git merge -s ours obsolete
250------------------------------------------------
251
252* Merge branch `maint` into the current branch, but do not make
253 a new commit automatically:
254+
255------------------------------------------------
256$ git merge --no-commit maint
257------------------------------------------------
258+
259This can be used when you want to include further changes to the
260merge, or want to write your own merge commit message.
261+
262You should refrain from abusing this option to sneak substantial
263changes into a merge commit. Small fixups like bumping
264release/version name would be acceptable.
265
266
267include::merge-strategies.adoc[]
268
269CONFIGURATION
270-------------
271
272`branch.<name>.mergeOptions`::
273 Sets default options for merging into branch _<name>_. The syntax and
274 supported options are the same as those of `git merge`, but option
275 values containing whitespace characters are currently not supported.
276
277include::includes/cmd-config-section-rest.adoc[]
278
279include::config/merge.adoc[]
280
281SEE ALSO
282--------
283linkgit:git-fmt-merge-msg[1], linkgit:git-pull[1],
284linkgit:gitattributes[5],
285linkgit:git-reset[1],
286linkgit:git-diff[1], linkgit:git-ls-files[1],
287linkgit:git-add[1], linkgit:git-rm[1],
288linkgit:git-mergetool[1]
289linkgit:gitmergeconflicts[7]
290
291GIT
292---
293Part of the linkgit:git[1] suite