Windows
git mergetool and git difftool
9 min read
This page covers two things that go together, in opposite directions:
- Versora as git's tool. You're in the terminal, you run
git mergetoolafter a merge with conflicts, and git opens Versora's conflict editor. Or you rungit difftooland see the diff in a Versora window. - An external tool opened by Versora. You're in the app and want to see a diff or resolve a conflict in the comparison program you already use. Versora opens that tool through git itself.
- Preferences › Command line and links › Versora as git mergetool and git difftool group.
- Palette (Ctrl+P): "Command line, links and git mergetool…".
The group shows the status of each tool (git mergetool and git difftool):
- "Configured (this Versora)." or "Configured with another executable: …" or "Not configured.";
- "It's the default tool (merge.tool = versora)." or "Default tool: …. Use git mergetool --tool=versora or check "Use as default"." or "No default tool: use git mergetool --tool=versora or check "Use as default".".
- Open Preferences › Command line and links.
- In the Versora as git mergetool and git difftool group, choose the options (table below).
- Click Configure… (if it's already configured, the button is Update…).
- The app shows the Write to the global git configuration? plan: "These commands write to …. Nothing is written until you confirm.". Each key that already had a value shows "now: …".
- Click Write. The notice "Configuration written to …" confirms it. If you'd rather run the commands yourself, use Copy commands.
| Option | What it does | Default |
|---|---|---|
| Use as default (merge.tool and diff.tool) | Writes merge.tool = versora and diff.tool = versora, so git mergetool and git difftool open Versora without --tool. | On |
| Don't keep .orig copies (mergetool.keepBackup = false) | Writes mergetool.keepBackup = false, so git doesn't leave .orig files behind after resolving. | Off |
The written commands go to git's global configuration (git config --global):
git config --global mergetool.versora.cmd '"<versora.exe>" mergetool "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config --global mergetool.versora.trustExitCode 'true'
git config --global difftool.versora.cmd '"<versora.exe>" difftool "$LOCAL" "$REMOTE" "$MERGED"'
git config --global merge.tool 'versora' # with "Use as default"
git config --global diff.tool 'versora' # with "Use as default"
git config --global mergetool.keepBackup 'false' # with "Don't keep .orig copies"
The executable's path goes with forward slashes (C:/…), which Git for Windows' shell
understands. trustExitCode makes git trust Versora's exit code: 0 is conflict resolved, 1
is not resolved.
The command line help (versora --help) also shows these commands.
-
In the terminal, a merge stops with a conflict:
$ git merge feature/pagamento CONFLICT (content): Merge conflict in src/carrinho.ts -
Run
git mergetool(orgit mergetool -y, so git doesn't ask for each file). -
The terminal shows "resolve the conflict in src/carrinho.ts in Versora. Git goes on when you save (or hand it back unresolved)." and waits.
-
Versora opens the repository tab and the usual conflict editor on the file. Below the tabs, the bar "git mergetool is waiting for carrinho.ts (loja-web). Resolve it in the conflict editor and save: the terminal moves on to the next file." appears.
-
Resolve and save in the editor. Versora writes the file and runs
git add. The terminal shows "src/carrinho.ts: conflict resolved in Versora." and git moves on to the next file. -
Repeat until the end and conclude the merge with
git commit(or from the app).
If Versora is closed, git itself opens it. The first launch may take a while: the command waits up to 90 seconds.
While git waits, the bar stays visible on any tab, because the terminal is stopped:
- Open the editor: reopens the file's conflict editor. Closing the editor does not hand the file back to git: the bar keeps warning.
- Hand back unresolved: "The conflict stays in the file; git mergetool reports that it wasn't
resolved." The git process exits with
1and the terminal shows "…: handed back unresolved by Versora.".
The file also counts as resolved if it stops being conflicted some other way, for example "Use the
version…" in the app or a git add in the terminal.
- In the terminal, run
git difftool(orgit difftool main feature/pagamento, orgit difftool -dto compare whole folders). - The terminal shows "showing the diff of … in Versora. Git goes on when you close the diff.".
- Versora opens the git difftool: … window (with the file name), with "file 2 of 5" when git passes several files, one at a time.
- Check Side by side to see both versions side by side (your choice is remembered).
- Click Close (or Esc): git moves on to the next file.
With git difftool -d (folder diff), the window lists the files ("… files"), each marked as
new, deleted or modified, with the line count (+12 −3).
| Code | Meaning |
|---|---|
0 | Conflict resolved (file saved and staged) or diff closed. |
1 | Not resolved, canceled, Versora closed midway or no answer. |
2 | Wrong usage, such as a file that isn't conflicted. |
Remove… takes Versora out of the git configuration. The Remove Versora from the git configuration? confirmation explains: "Removes mergetool.versora and difftool.versora from …" and "merge.tool and diff.tool go back to what they were (…)." (if there was another tool before) or "merge.tool and diff.tool are removed if they're Versora.". Click Remove. The notice "Versora removed from …" confirms it.
A conflict resolved through git mergetool stays staged, as in the conflict editor. To start the
file over, use the conflict features.
- "… isn't conflicted. Versora as mergetool resolves the conflicted files of git mergetool.":
versora mergetoolwas called with a file that isn't conflicted. - "git mergetool stopped waiting for ….": the git process ended first (for example, Ctrl+C in the terminal, or the terminal was closed).
- "Versora was closed before finishing.": you closed the app while git was waiting. Git treats it as not resolved.
- "Binary file: there's no text diff." and "Both sides are the same.": notices in the difftool window.
- "No differences between the folders.": in
git difftool -d, the folders are the same. - "… is too large to show the diff.": files above 20 MB aren't shown.
- "One side is a folder and the other is a file: they can't be compared.": git passed an inconsistent pair.
- "Couldn't write the git configuration: …": the global configuration is locked or there's no permission.
Tip
In a Command Prompt or PowerShell terminal, git mergetool and git difftool wait for Versora
normally, because it's git that calls Versora, and git waits for the process to finish.
- Preferences › Command line and links (id
deeplinkfor the company policy). See Policy keys.
If you already use a comparison program, Versora can open it to show a file's diff or to resolve a
conflict. It's git itself that opens the tool (git difftool and git mergetool), so the same
configuration as in the terminal applies.
- Configuration: Preferences › Operations › Diff and merge tools group.
- Palette (Ctrl+P): "Operations preferences".
- To open the diff tool:
- Open in external diff tool button, in the diff header;
- file menu › Open in diff tool.
- To open the merge tool:
- Merge tool button ("Open this file in the external merge tool"), in the conflict editor;
- menu of a conflicted file › Open in merge tool.
Each of the two tools (Diff tool and Merge tool) has the same choices:
| Option | What it does | Default |
|---|---|---|
| Git's (…) | Uses the tool from the git configuration (diff.tool or merge.tool). With none, Git's (none configured) appears. | Yes |
| A tool by name | The tools git knows and found installed on this machine (the git difftool --tool-help list). | — |
| Custom… | A Command line of your own, with $LOCAL, $REMOTE, $BASE and $MERGED in quotes. | — |
Examples of a custom command line (replace with your tool's path):
Diff: "C:\Ferramentas\compara.exe" "$LOCAL" "$REMOTE"
Merge: "C:\Ferramentas\compara.exe" "$LOCAL" "$REMOTE" "$BASE" -o "$MERGED"
| Variable | What it is |
|---|---|
$LOCAL | Your version (the current side). |
$REMOTE | The incoming version (the received side). |
$BASE | The common ancestor of the two, in the merge. |
$MERGED | The repository file where the result must end up, in the merge. |
Caution
Prefer windowed tools. The ones that run inside a terminal (such as vimdiff) don't show up, because the app opens the tool without a terminal.
- In Preferences › Operations, choose the Merge tool.
- In the "Conflicted" section of the changes panel, open the file in the conflict editor.
- Click Merge tool. The notice "Opening … in the merge tool…" appears and the tool opens.
- Resolve and save in the tool, and close it.
- If the merge was concluded, the file is marked as resolved: "… resolved in the merge tool". Otherwise: "The merge tool closed without finishing … (code …): the file is still conflicted.".
For the diff, the app runs git difftool with the chosen tool and the right pair of versions (the
working directory, staging with --cached, a commit against its parent or two revisions):
git difftool --tool=<tool> -y --no-prompt [--cached | -M <from> <to>] -- <file>
For the merge, the app runs git mergetool on the file only, without .orig copies or temporary
files:
git -c mergetool.keepBackup=false -c mergetool.keepTemporaries=false mergetool --tool=<tool> -y --no-prompt -- <file>
With Git's, --tool isn't passed, and diff.tool or merge.tool applies. With Custom…,
the app passes your command line in a -c option for that command only, without writing anything
to the git configuration (and, in the merge, it trusts the tool's exit code).
The external tool only changes the conflicted file. As long as the merge isn't concluded, you can go back to Versora's conflict editor. What's already resolved stays staged, as with any resolution. See Conflicts.
- "No diff tool is configured in git (diff.tool). Choose one in Preferences › Operations." and "No merge tool is configured in git (merge.tool). Choose one in Preferences › Operations.": with Git's, git has no tool configured. Without one, git would try a terminal tool, which would get stuck: the app refuses beforehand.
- "Enter the custom tool's command line in Preferences › Operations.": the Custom… option has no command.
- "Invalid tool name: …": the chosen name has a space or starts with
-. - "New file: there's no previous version to compare with": an untracked file doesn't have the other side of the diff.
- "The merge tool only opens content conflicts (the file exists on both sides).": deletion and submodule conflicts are resolved in the app's conflict editor.
- "Couldn't open the diff tool" and "Couldn't open the merge tool": the window shows the error and the Open preferences button.
- Preferences › Operations › Diff and merge tools.
- The Operations page can be hidden or made read-only by the company policy (id
ergoOps). See Policy keys.
- Conflict editor
- Diff
- Command line
- Git documentation: git mergetool (opens another site) and git difftool (opens another site)