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