Skip to content
Versora

Manual

Windows

git mergetool and git difftool

9 min read

On this page

This page covers two things that go together, in opposite directions:

  1. Versora as git's tool. You're in the terminal, you run git mergetool after a merge with conflicts, and git opens Versora's conflict editor. Or you run git difftool and see the diff in a Versora window.
  2. 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.

Versora as git mergetool and git difftool

Where to find it

  • 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".".

Step by step: configure

  1. Open Preferences › Command line and links.
  2. In the Versora as git mergetool and git difftool group, choose the options (table below).
  3. Click Configure… (if it's already configured, the button is Update…).
  4. 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: …".
  5. Click Write. The notice "Configuration written to …" confirms it. If you'd rather run the commands yourself, use Copy commands.
OptionWhat it doesDefault
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

What Versora does in git

The written commands go to git's global configuration (git config --global):

bash
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.

Step by step: resolve conflicts with git mergetool

  1. In the terminal, a merge stops with a conflict:

    $ git merge feature/pagamento
    CONFLICT (content): Merge conflict in src/carrinho.ts
    
  2. Run git mergetool (or git mergetool -y, so git doesn't ask for each file).

  3. 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.

  4. 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.

  5. 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.

  6. 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.

The mergetool bar

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 1 and 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.

Step by step: see diffs with git difftool

  1. In the terminal, run git difftool (or git difftool main feature/pagamento, or git difftool -d to compare whole folders).
  2. The terminal shows "showing the diff of … in Versora. Git goes on when you close the diff.".
  3. Versora opens the git difftool: … window (with the file name), with "file 2 of 5" when git passes several files, one at a time.
  4. Check Side by side to see both versions side by side (your choice is remembered).
  5. 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).

Exit codes

CodeMeaning
0Conflict resolved (file saved and staged) or diff closed.
1Not resolved, canceled, Versora closed midway or no answer.
2Wrong usage, such as a file that isn't conflicted.

How to undo

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.

Caveats and messages

  • "… isn't conflicted. Versora as mergetool resolves the conflicted files of git mergetool.": versora mergetool was 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 deeplink for the company policy). See Policy keys.

External diff and merge tool

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.

Where to find it

  • 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:

OptionWhat it doesDefault
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 nameThe 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"
VariableWhat it is
$LOCALYour version (the current side).
$REMOTEThe incoming version (the received side).
$BASEThe common ancestor of the two, in the merge.
$MERGEDThe 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.

Step by step: resolve a conflict in the external tool

  1. In Preferences › Operations, choose the Merge tool.
  2. In the "Conflicted" section of the changes panel, open the file in the conflict editor.
  3. Click Merge tool. The notice "Opening … in the merge tool…" appears and the tool opens.
  4. Resolve and save in the tool, and close it.
  5. 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.".

What Versora does in git

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):

bash
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:

bash
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).

How to undo

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.

Caveats and messages

  • "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.

See also