MagnumOpus Diff and merging
MagnumOpus Diff (mo-diff.exe, next to the explorer) is a separate app for working with differences. It has three windows: comparing and editing two files side by side, a three-way merge for git conflicts and folder compare with synchronization (see Comparing and synchronizing folders). Every window is its own process that waits until you close it, so it also works as a git tool from the terminal.
Opening it
From the explorer:
- Select two files and choose Compare in the context menu.
- In a repository: Git > Compare with HEAD, the compare button in the Changes tab, Compare with working copy in History, or a double click on a file of a commit (see Git in folders).
- A file in conflict: Resolve in MagnumOpus Diff in its Changes bar or the Git submenu.
- Two folders: Compare folders (MagnumOpus Diff)… in the command palette of a split window.
Versions from git are written to temporary files and the sides get titles such as Cargo.toml (HEAD c4c3576) and Cargo.toml (working copy). When mo-diff.exe is missing, Compare falls back to the comparison in MagnumOpus View.
Comparing two files
Both files are shown side by side. Each panel shows only its own lines and both scroll together: unchanged parts stay aligned and a change of a different height catches up as it passes the middle of the window, like in IntelliJ. Bands between the panels connect each change on the left with its place on the right.
- Modified blocks are blue, added green, removed red; the changed part of a line is stronger.
- F7 / Shift+F7 or the arrows in the toolbar jump to the next / previous change ("3 / 12"). A click selects a change, the scrollbar shows a map of all of them.
- Collapse unchanged folds unchanged blocks into one line with the number of lines; a click expands them.
- Whitespace: Compare, Ignore trailing, or Ignore.
- Wrap lines (toolbar button or Alt+Z) wraps long lines to the window width - in a comparison, in the editor and in the three-way merge. The lines of both sides stay aligned and the choice is remembered.
- Show next to the whitespace comparison options displays spaces and tabs, so a difference only in them is visible.
- Swap sides, Reload (F5). When a file changes on disk, it reloads by itself as soon as you switch back to the window.
- Syntax highlighting in VS Code colors (Dark+ / Light+ by the theme), computed in the background.
- The same formats as in MagnumOpus View are colored, including Latte templates, files without an extension (
.htaccess,Dockerfile) and your own syntaxes. - Encodings are detected like in the text preview (cp1250, UTF-16, BOM) from the whole file. The status bar shows the encoding and line endings of both sides.
- Binary files only report whether they are identical. Files can have up to 512 MB.
- Esc closes the window.
The difference is computed in the background - two files of 10,000 lines take about 1 ms.
Editing both files
Both sides of a comparison can be edited. Click anywhere to place the cursor and type; select with the mouse or with Shift and the arrows, Ctrl+arrows move by words, Ctrl+C / Ctrl+X / Ctrl+V work as usual. The comparison updates after a short pause in typing.
Moving changes. Every change has arrows in the strip between the panels that move it to the other side. Alt+Left / Alt+Right do the same for the current change, and Move all changes to the right / Move all changes to the left in the toolbar move all of them at once.
Undo. There is one Undo / Redo for both sides (Ctrl+Z / Ctrl+Y); typing is undone by words.
Find and replace. Ctrl+F opens Find and replace. It can also search with a regular expression (.*) and use groups such as $1 in the replacement. Replace all is a single Undo step.
Saving
- Ctrl+S saves the side with the cursor, Ctrl+Shift+S saves both.
- The file keeps its original encoding, BOM and line endings. When the text contains characters the encoding can't store, it asks whether to save the file as UTF-8.
- When another program changed the file since it was opened, it asks before overwriting it. Closing the window with unsaved changes asks too.
- A symbolic link stays a link (its target is saved). Hard links, attributes and permissions of the file are kept.
- A file on an SFTP / FTP server or a phone is edited through a temporary copy and saved straight back - only when it has not changed there in the meantime.
Some sides stay read only: versions from git, files inside archives, binary or too large files, and sides opened with --readonly-left / --readonly-right.
When saving fails because the file is in use
When another program holds the file, the notice names it - for example "Saving failed - Used by: Microsoft Word" - and offers Who is using the file. The window lists the programs with their PID and what they hold. Close program asks the program to close; it asks about its own unsaved documents itself. When it doesn't close, Force quit is offered, which takes a second click (unsaved work in that program is lost). Once nobody holds the file, Save again (Enter) finishes the save - your edits stay in the window the whole time.
The same works when saving a merge.
Comparing from the conflict dialog
When a copy meets names that are already taken, every file in the dialog has a Compare button that opens the source and the existing file side by side in MagnumOpus Diff - with the choice of which to keep and the option to edit the target. See Copying and conflicts.
Three-way merge
mo-diff --merge <ours> <theirs> <base> <output>
The window shows three panels: Ours | Result | Theirs, with the lines of each block aligned across the panels. The Base toggle in the toolbar adds the base as a fourth panel on the left (the choice is remembered). Changed parts of lines are highlighted against the base - in ours and theirs what each side changed, in the base both.
Resolving conflicts
- Changes that do not conflict are already in the result, like in git. The cross next to such a change returns that block to the base.
- An unresolved conflict shows the base text dimmed in the result - what both sides started from.
- An arrow in the band takes that side into the result. Both arrows take both sides, in the order you clicked them; the cross removes a side again.
- When both sides only added lines in the same place (a CHANGELOG, imports), the block offers Ours, then theirs and Theirs, then ours.
- The pencil or a double click edits any block of the result right in the window, including unchanged text around conflicts. Ctrl+Enter or a click outside confirms, Esc cancels. An edited block has a button to revert the edit.
Resolve simple resolves the safe conflicts by itself - both sides made the same change, the difference is only in whitespace at line ends, or each side changed a different part of a line - and marks them yellow so you can review them.
Keys
| Key | Action |
|---|---|
| F7 / Shift+F7 | next / previous conflict |
| Alt+Left / Alt+Right | take a side for the selected block |
| Ctrl+Z / Ctrl+Y | undo / redo a step |
| Ctrl+S | save |
Saving the merge
Save and close writes the result. Lines taken from the versions are written byte for byte with their own line endings; your own text (edits, conflict markers) gets the encoding and line endings of "ours". Unresolved conflicts make it ask first and are written with markers like git's. When the output file was changed by another program since the window opened, it asks before overwriting it. Closing with unsaved changes asks too.
From the explorer, saving without conflicts marks the file resolved in git by itself (git add).
Exit codes
| Code | Meaning |
|---|---|
| 0 | merge saved without conflicts and not changed since |
| 1 | cancelled, or conflicts left |
Folder synchronization from scripts has its own exit codes, see Comparing and synchronizing folders.
Using it from the terminal
mo-diff <left> <right> [--title-left=T] [--title-right=T]
mo-diff --merge <ours> <theirs> <base> <output>
mo-diff --dir <left folder> <right folder>
mo-diff --profile=<profile>
--readonly-left and --readonly-right open a side of a file comparison read only.
The process waits until the window is closed, so git can use it as difftool and mergetool:
git config --global difftool.mo.cmd 'mo-diff "$LOCAL" "$REMOTE"'
git config --global mergetool.mo.cmd 'mo-diff --merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"'
git config --global mergetool.mo.trustExitCode true
(Written for PowerShell or Git Bash - the single quotes keep $LOCAL and the others for git.)
Then git difftool --tool=mo and git mergetool --tool=mo. Use the full path to mo-diff.exe when its folder is not in PATH.
Inside MagnumOpus Explorer no configuration is needed. Settings > Git > Merge tool chooses which tool resolves conflicts - MagnumOpus Diff or another one that was found.