1GIT-MERGETOOL(1) Git Manual GIT-MERGETOOL(1)
2
3
4
6 git-mergetool - Run merge conflict resolution tools to resolve merge
7 conflicts
8
10 git mergetool [--tool=<tool>] [-y | --[no-]prompt] [<file>...]
11
13 Use git mergetool to run one of several merge utilities to resolve
14 merge conflicts. It is typically run after git merge.
15
16 If one or more <file> parameters are given, the merge tool program will
17 be run to resolve differences in each file (skipping those without
18 conflicts). Specifying a directory will include all unresolved files in
19 that path. If no <file> names are specified, git mergetool will run the
20 merge tool program on every file with merge conflicts.
21
23 -t <tool>, --tool=<tool>
24 Use the merge resolution program specified by <tool>. Valid values
25 include emerge, gvimdiff, kdiff3, meld, vimdiff, and tortoisemerge.
26 Run git mergetool --tool-help for the list of valid <tool>
27 settings.
28
29 If a merge resolution program is not specified, git mergetool will
30 use the configuration variable merge.tool. If the configuration
31 variable merge.tool is not set, git mergetool will pick a suitable
32 default.
33
34 You can explicitly provide a full path to the tool by setting the
35 configuration variable mergetool.<tool>.path. For example, you can
36 configure the absolute path to kdiff3 by setting
37 mergetool.kdiff3.path. Otherwise, git mergetool assumes the tool is
38 available in PATH.
39
40 Instead of running one of the known merge tool programs, git
41 mergetool can be customized to run an alternative program by
42 specifying the command line to invoke in a configuration variable
43 mergetool.<tool>.cmd.
44
45 When git mergetool is invoked with this tool (either through the -t
46 or --tool option or the merge.tool configuration variable), the
47 configured command line will be invoked with $BASE set to the name
48 of a temporary file containing the common base for the merge, if
49 available; $LOCAL set to the name of a temporary file containing
50 the contents of the file on the current branch; $REMOTE set to the
51 name of a temporary file containing the contents of the file to be
52 merged, and $MERGED set to the name of the file to which the merge
53 tool should write the result of the merge resolution.
54
55 If the custom merge tool correctly indicates the success of a merge
56 resolution with its exit code, then the configuration variable
57 mergetool.<tool>.trustExitCode can be set to true. Otherwise, git
58 mergetool will prompt the user to indicate the success of the
59 resolution after the custom tool has exited.
60
61 --tool-help
62 Print a list of merge tools that may be used with --tool.
63
64 -y, --no-prompt
65 Don’t prompt before each invocation of the merge resolution
66 program. This is the default if the merge resolution program is
67 explicitly specified with the --tool option or with the merge.tool
68 configuration variable.
69
70 --prompt
71 Prompt before each invocation of the merge resolution program to
72 give the user a chance to skip the path.
73
74 -g, --gui
75 When git-mergetool is invoked with the -g or --gui option, the
76 default merge tool will be read from the configured merge.guitool
77 variable instead of merge.tool. If merge.guitool is not set, we
78 will fallback to the tool configured under merge.tool. This may be
79 autoselected using the configuration variable mergetool.guiDefault.
80
81 --no-gui
82 This overrides a previous -g or --gui setting or
83 mergetool.guiDefault configuration and reads the default merge tool
84 from the configured merge.tool variable.
85
86 -O<orderfile>
87 Process files in the order specified in the <orderfile>, which has
88 one shell glob pattern per line. This overrides the diff.orderFile
89 configuration variable (see git-config(1)). To cancel
90 diff.orderFile, use -O/dev/null.
91
93 Everything below this line in this section is selectively included from
94 the git-config(1) documentation. The content is the same as what’s
95 found there:
96
97 mergetool.<tool>.path
98 Override the path for the given tool. This is useful in case your
99 tool is not in the PATH.
100
101 mergetool.<tool>.cmd
102 Specify the command to invoke the specified merge tool. The
103 specified command is evaluated in shell with the following
104 variables available: BASE is the name of a temporary file
105 containing the common base of the files to be merged, if available;
106 LOCAL is the name of a temporary file containing the contents of
107 the file on the current branch; REMOTE is the name of a temporary
108 file containing the contents of the file from the branch being
109 merged; MERGED contains the name of the file to which the merge
110 tool should write the results of a successful merge.
111
112 mergetool.<tool>.hideResolved
113 Allows the user to override the global mergetool.hideResolved value
114 for a specific tool. See mergetool.hideResolved for the full
115 description.
116
117 mergetool.<tool>.trustExitCode
118 For a custom merge command, specify whether the exit code of the
119 merge command can be used to determine whether the merge was
120 successful. If this is not set to true then the merge target file
121 timestamp is checked, and the merge is assumed to have been
122 successful if the file has been updated; otherwise, the user is
123 prompted to indicate the success of the merge.
124
125 mergetool.meld.hasOutput
126 Older versions of meld do not support the --output option. Git will
127 attempt to detect whether meld supports --output by inspecting the
128 output of meld --help. Configuring mergetool.meld.hasOutput will
129 make Git skip these checks and use the configured value instead.
130 Setting mergetool.meld.hasOutput to true tells Git to
131 unconditionally use the --output option, and false avoids using
132 --output.
133
134 mergetool.meld.useAutoMerge
135 When the --auto-merge is given, meld will merge all non-conflicting
136 parts automatically, highlight the conflicting parts, and wait for
137 user decision. Setting mergetool.meld.useAutoMerge to true tells
138 Git to unconditionally use the --auto-merge option with meld.
139 Setting this value to auto makes git detect whether --auto-merge is
140 supported and will only use --auto-merge when available. A value of
141 false avoids using --auto-merge altogether, and is the default
142 value.
143
144 mergetool.vimdiff.layout
145 The vimdiff backend uses this variable to control how its split
146 windows appear. Applies even if you are using Neovim (nvim) or gVim
147 (gvim) as the merge tool. See BACKEND SPECIFIC HINTS section for
148 details.
149
150 mergetool.hideResolved
151 During a merge, Git will automatically resolve as many conflicts as
152 possible and write the MERGED file containing conflict markers
153 around any conflicts that it cannot resolve; LOCAL and REMOTE
154 normally represent the versions of the file from before Git’s
155 conflict resolution. This flag causes LOCAL and REMOTE to be
156 overwritten so that only the unresolved conflicts are presented to
157 the merge tool. Can be configured per-tool via the
158 mergetool.<tool>.hideResolved configuration variable. Defaults to
159 false.
160
161 mergetool.keepBackup
162 After performing a merge, the original file with conflict markers
163 can be saved as a file with a .orig extension. If this variable is
164 set to false then this file is not preserved. Defaults to true
165 (i.e. keep the backup files).
166
167 mergetool.keepTemporaries
168 When invoking a custom merge tool, Git uses a set of temporary
169 files to pass to the tool. If the tool returns an error and this
170 variable is set to true, then these temporary files will be
171 preserved; otherwise, they will be removed after the tool has
172 exited. Defaults to false.
173
174 mergetool.writeToTemp
175 Git writes temporary BASE, LOCAL, and REMOTE versions of
176 conflicting files in the worktree by default. Git will attempt to
177 use a temporary directory for these files when set true. Defaults
178 to false.
179
180 mergetool.prompt
181 Prompt before each invocation of the merge resolution program.
182
183 mergetool.guiDefault
184 Set true to use the merge.guitool by default (equivalent to
185 specifying the --gui argument), or auto to select merge.guitool or
186 merge.tool depending on the presence of a DISPLAY environment
187 variable value. The default is false, where the --gui argument must
188 be provided explicitly for the merge.guitool to be used.
189
191 git mergetool creates *.orig backup files while resolving merges. These
192 are safe to remove once a file has been merged and its git mergetool
193 session has completed.
194
195 Setting the mergetool.keepBackup configuration variable to false causes
196 git mergetool to automatically remove the backup files as files are
197 successfully merged.
198
200 vimdiff
201 Description
202 When specifying --tool=vimdiff in git mergetool Git will open Vim
203 with a 4 windows layout distributed in the following way:
204
205 ------------------------------------------
206 | | | |
207 | LOCAL | BASE | REMOTE |
208 | | | |
209 ------------------------------------------
210 | |
211 | MERGED |
212 | |
213 ------------------------------------------
214
215 LOCAL, BASE and REMOTE are read-only buffers showing the contents
216 of the conflicting file in specific commits ("commit you are
217 merging into", "common ancestor commit" and "commit you are merging
218 from" respectively)
219
220 MERGED is a writable buffer where you have to resolve the conflicts
221 (using the other read-only buffers as a reference). Once you are
222 done, save and exit Vim as usual (:wq) or, if you want to abort,
223 exit using :cq.
224
225 Layout configuration
226 You can change the windows layout used by Vim by setting
227 configuration variable mergetool.vimdiff.layout which accepts a
228 string where the following separators have special meaning:
229
230 • + is used to "open a new tab"
231
232 • , is used to "open a new vertical split"
233
234 • / is used to "open a new horizontal split"
235
236 • @ is used to indicate the file containing the final version
237 after solving the conflicts. If not present, MERGED will be
238 used by default.
239
240 The precedence of the operators is as follows (you can use
241 parentheses to change it):
242
243 `@` > `+` > `/` > `,`
244
245 Let’s see some examples to understand how it works:
246
247 • layout = "(LOCAL,BASE,REMOTE)/MERGED"
248
249 This is exactly the same as the default layout we have already
250 seen.
251
252 Note that / has precedence over , and thus the parenthesis are
253 not needed in this case. The next layout definition is
254 equivalent:
255
256 layout = "LOCAL,BASE,REMOTE / MERGED"
257
258 • layout = "LOCAL,MERGED,REMOTE"
259
260 If, for some reason, we are not interested in the BASE buffer.
261
262 ------------------------------------------
263 | | | |
264 | | | |
265 | LOCAL | MERGED | REMOTE |
266 | | | |
267 | | | |
268 ------------------------------------------
269
270 • layout = "MERGED"
271
272 Only the MERGED buffer will be shown. Note, however, that all
273 the other ones are still loaded in vim, and you can access them
274 with the "buffers" command.
275
276 ------------------------------------------
277 | |
278 | |
279 | MERGED |
280 | |
281 | |
282 ------------------------------------------
283
284 • layout = "@LOCAL,REMOTE"
285
286 When MERGED is not present in the layout, you must "mark" one
287 of the buffers with an asterisk. That will become the buffer
288 you need to edit and save after resolving the conflicts.
289
290 ------------------------------------------
291 | | |
292 | | |
293 | | |
294 | LOCAL | REMOTE |
295 | | |
296 | | |
297 | | |
298 ------------------------------------------
299
300 • layout = "LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL +
301 BASE,REMOTE"
302
303 Three tabs will open: the first one is a copy of the default
304 layout, while the other two only show the differences between
305 (BASE and LOCAL) and (BASE and REMOTE) respectively.
306
307 ------------------------------------------
308 | <TAB #1> | TAB #2 | TAB #3 | |
309 ------------------------------------------
310 | | | |
311 | LOCAL | BASE | REMOTE |
312 | | | |
313 ------------------------------------------
314 | |
315 | MERGED |
316 | |
317 ------------------------------------------
318
319 ------------------------------------------
320 | TAB #1 | <TAB #2> | TAB #3 | |
321 ------------------------------------------
322 | | |
323 | | |
324 | | |
325 | BASE | LOCAL |
326 | | |
327 | | |
328 | | |
329 ------------------------------------------
330
331 ------------------------------------------
332 | TAB #1 | TAB #2 | <TAB #3> | |
333 ------------------------------------------
334 | | |
335 | | |
336 | | |
337 | BASE | REMOTE |
338 | | |
339 | | |
340 | | |
341 ------------------------------------------
342
343 • layout = "LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE
344 + (LOCAL/BASE/REMOTE),MERGED"
345
346 Same as the previous example, but adds a fourth tab with the
347 same information as the first tab, with a different layout.
348
349 ---------------------------------------------
350 | TAB #1 | TAB #2 | TAB #3 | <TAB #4> |
351 ---------------------------------------------
352 | LOCAL | |
353 |---------------------| |
354 | BASE | MERGED |
355 |---------------------| |
356 | REMOTE | |
357 ---------------------------------------------
358
359 Note how in the third tab definition we need to use parentheses
360 to make , have precedence over /.
361
362 Variants
363 Instead of --tool=vimdiff, you can also use one of these other
364 variants:
365
366 • --tool=gvimdiff, to open gVim instead of Vim.
367
368 • --tool=nvimdiff, to open Neovim instead of Vim.
369
370 When using these variants, in order to specify a custom layout you
371 will have to set configuration variables mergetool.gvimdiff.layout
372 and mergetool.nvimdiff.layout instead of mergetool.vimdiff.layout
373
374 In addition, for backwards compatibility with previous Git
375 versions, you can also append 1, 2 or 3 to either vimdiff or any of
376 the variants (ex: vimdiff3, nvimdiff1, etc...) to use a predefined
377 layout. In other words, using --tool=[g,n,]vimdiffx is the same as
378 using --tool=[g,n,]vimdiff and setting configuration variable
379 mergetool.[g,n,]vimdiff.layout to...
380
381 • x=1: "@LOCAL, REMOTE"
382
383 • x=2: "LOCAL, MERGED, REMOTE"
384
385 • x=3: "MERGED"
386
387 Example: using --tool=gvimdiff2 will open gvim with three columns
388 (LOCAL, MERGED and REMOTE).
389
391 Part of the git(1) suite
392
393
394
395Git 2.43.0 11/20/2023 GIT-MERGETOOL(1)