Northern Commander

Diffs and patches

A .diff or .patch file opens as the changes it describes: a line for each file it changes, then each change with its lines numbered as they were and as they become, colored as the file’s language. Any file or change can be copied out as a patch of its own.

Two files. The second was renamed, which is said under its line; the band says which file the cursor is in.

What the keys do

Key For a patch
Enter Hands it to the application macOS opens patches with
F3 Shows the changes, as above
⇧F3 Shows its text in the text viewer, colored as Diff
F4 Opens its text in the built-in editor, colored as Diff

Opening files says how to change them.

Recognized by

The extensions .diff and .patch. It reads unified diffs — what git diff, git format-patch and diff -u write — and git’s own lines about renames, copies, new and deleted files, modes and binary files.

At a glance

KeyAction
⌘↓Next change
⌘↑Previous change
⌥→Next file of the difference
⌥←Previous file of the difference
F5Copy this file's difference
⇧F5Copy this hunk
F8Side by side
F7Search…
⇧F9All it says about itself
⌥F3Compare files…
F6Ignore white space
⇧F6Swap the two sides
⌘→Take into the right file
⌘←Take into the left file

Reading it

A file’s line
Its name, with how many lines it adds and removes on the right. Under it, anything else that happened to it: renamed or copied from another name and how alike they are, new, deleted, its mode changed, or binary.
A change
Its @@ line, as the patch writes it, then its lines: the number each had before and after, - on a red ground for a line taken out, + on green for a line put in. A line that says nothing about a file — a commit message, the summary git writes — is shown as it is, grayed.

The cursor is a line: ↑ and ↓ move it, Page Up and Page Down a screen, Home and End to the start and the end, and a click puts it where you click. ← and → move long lines sideways. The band along the bottom says which file the cursor is in, and which change.

  • ⌘↓ and ⌘↑ go to the next run of changed lines and the one before: removed and added lines with no unchanged line between them. One @@ line can have several under it.
  • ⌥→ and ⌥← go to the next file’s line and the one before. While a patch is open these are the keys that otherwise step through the pane’s files.
  • The colors come a moment after the text, a file at a time. Removed and added lines are colored separately, so something a removed line opened — a comment, a string — does not spill onto the added ones.

The line under the patch counts the files, the lines added and the lines removed.

Side by side

F8 puts the two sides beside each other, and pressed again puts them back one under the other. Whichever you used last is how the next patch or comparison opens, kept as Differences side by side.

Each line stands beside what it became. Lines only one side has stand beside nothing.
  • What was there before is on the left and what is there now on the right, each with its own line numbers. A line that was edited stands beside what it became; a line only one side has stands beside nothing.
  • Long lines are not wrapped: ← and → slide both sides together.
  • Finding looks through the left of a row and then its right.
  • It needs a window at least 80 columns wide. In a narrower one the changes are shown one under the other, with a line along the bottom saying why, and go side by side again when the window is widened.

Patches that do not add up

Patches are edited by hand and pasted into mail, so they are read as they are rather than refused:

  • A change whose lines do not match the counts in its @@ line keeps the lines it has, and says so in yellow beside that line.
  • A blank line inside a change is taken as an unchanged line whose leading space was lost.
  • A change with no file before it is shown as A change to a file it does not name.

Finding in it

F7 asks what to look for, with Match case and Regular expression, and Find next or Find previous. It looks through every line shown — names, @@ lines, the lines of each change, the message — and comes round at the end. F3 and ⇧F3 look again.

Comparing two files

⌥F3 shows what one file has that another does not: its own lines as added, the other’s as removed.

Green is what the file compared has. Edited lines show which part of them changed.
Which two
The key asks, with what the panes suggest already filled in, so Enter compares them. Compare is the file under the cursor, or the one marked. With is one in the other pane: the one marked there, or the one under its cursor, or failing both the file there with the same name. Mark two files in one pane and the upper one is compared with the lower.
Either path can be typed over. One the panes offer nothing for is left empty.
Changing them
Type over either path, or recall one compared before from the field’s history. Swap makes the two change places. A path that is not a file is refused when Compare is pressed, with the reason under the fields.
What is shown
The two files under the name, the other one after a − and the one compared after a +, then the changes with three unchanged lines round each. Where a line was edited, the part of it that changed is on a brighter ground. Everything above about reading, finding and copying applies; a copy is a patch that turns the other file into the one compared.
  • F6 takes lines that differ only in how much white space they have, or in white space at either end, as the same; pressed again, or with the box in the dialog cleared, white space is compared too. The box is checked until you change it. After that the dialog opens with it as the last comparison left it, by the box or the key, until the window closes.
  • ⇧F6 compares the two the other way round.
  • F8 puts the other file on the left and the one compared on the right, each named over its own side — Side by side.
  • F4 shows the comparison as the text of a patch.

Each file is read in its own encoding, and what ends a line is not part of the line. Two files that differ only in those have no changed lines, and the line under the name says how they differ. Two files with nothing between them say The two files are identical.

A file that is not text, or that is past the limits below, is compared byte for byte: the line under the name says whether the two are the same, and at which byte they first differ.

Taking a change across

While two text files are compared you can take a change from one into the other, and save.

  • ⌘→ puts the left file’s version of the change into the right file, and ⌘← the right file’s into the left. The left file is the other file and the right file the one compared, whether or not they are side by side; the line along the bottom names the file that changed.
  • ⌘↓ and ⌘↑ put the cursor on a whole run of changed lines, which is marked from its first line to its last, and the whole of it is taken.
  • Move the cursor within it and one line is taken instead. A line that was edited replaces the line it became. Any other line is put into the other file. Where the side you take from has no line there, the other side’s line is removed.
  • Side by side, a row can hold a line of each file that are not one line edited. A press takes the line of the file you take from, and the two part: the line that was beside it gets a row of its own, where you can take it out. Holding the key down takes once.
  • F2 writes the files that changed. It asks once, naming them, and nothing is written before that. Each file keeps its encoding, its line endings and its permissions. A file somebody has written to since it was compared is asked about first. A read-only file in a folder you can write to is replaced, as it is when you save from the editor.
  • Closing with takes that are not saved asks whether to save them.

What you have taken stays in view

A change you have taken stays in view until you save, and the file it went into is shown as the save will write it. Text that is struck through goes; everything else on the amber ground will be in the file.

The right side is shown as the save will write it. What goes is struck through.
  • A mark in front of each line points at the file the take changes: » for the right file, « for the left.
  • A line that arrives is shown in full, on amber.
  • A line with a small edit is shown as the line it becomes: the part that goes struck through, and the part that arrives right after it on a brighter ground.
  • A line changed in several places is shown as two: the old line struck through, and the new line under it. A change that rewrites a block is shown the same way, with every line that goes first and then every line that arrives.
  • White space is never struck through. A line that only changes its indent is shown as it will be, at the column it will have.
  • Only a line that is taken out is struck through whole. Lines that go stand above the lines that arrive in their place.
  • The line numbers of that file are the ones it will have once saved, so a line that goes has none.
  • The file you took from does not change, and is drawn without the amber: only the mark says a line of it was taken. One under the other, a line that is now in both files is one row with both its numbers.
  • On a taken line the cursor’s bar covers the numbers and the mark only, so the line stays readable.
  • A line too long for its side says with … at the edge that a part that goes or arrives is out of sight; → and ← bring it in. A line you have not taken says the same where the part that differs is out of sight.
  • ⌘↓ and ⌘↑ still stop on it, and the line along the bottom says it is taken and into which file.
  • The right of that line counts the changes taken into each file and not saved, such as « 1 taken into left, » 2 into right, not saved, so you know which files a save writes.

To put one take back, press the opposite key on it: ⌘← on a change taken into the right file, and ⌘→ on one taken into the left. It does not matter what you took after it. That press takes nothing, so press again to take the change the other way. The line above the key bar says what each key does where the cursor is.

⌘Z goes back through takes and put-backs in the order you made them, and ⇧⌘Z makes them again.

Once saved, what was taken is what the files hold. The two are compared again, those changes are no longer shown, and undo does not reach back past the save.

While anything taken is not saved, F6 and ⇧F6 wait: save or undo first.

If a file you take from has been written to by something else, it is read again and the two are compared again. Takes that are not saved cannot be kept through that, so you are asked first whether to save them or discard them.

Where a save wrote one file and could not write the other, what was taken into the file written is drawn in gray and stays as it is. What was taken into the other is still counted, and can be saved again or put back.

While white space is ignored, lines that differ only in white space are not offered, and are left as they are. Nothing can be taken in a patch, or where a file is not text or is too large to edit; the key says why.

Copying from it

F5 copies the changes to the file the cursor is in, and ⇧F5 the change it is in, each as a patch of its own: the file’s header as the patch has it, and the counts in each @@ line worked out again from its lines — so a change that did not add up applies once copied.

What the panel lists

Choose a file here to go to it.
Changes
How many files, lines added and removed, and changes, and how many changes do not add up.
Message
The subject, author and date, where the patch starts with them, as git format-patch writes them.
Files
Every file the patch changes. Choose one with the arrows and press Enter, or click it twice, to go to it.
Limits
How much of the patch was held, where it was not all of it.
File
The patch’s own encoding and line endings.

When it is not a diff

  • A file with nothing that reads as a diff in its first megabyte opens in the text viewer.
  • At most a million lines, or 32 million characters, are held; past that the line under the patch says not the whole file, and the panel says how much was. A single line longer than 1 MB stops the reading.

Editing it

F4 opens the patch’s text in the built-in editor, colored as Diff. There is no view of its changes there — see Editing files.

Limits

  • The older context diff, with *** lines, is not read as changes.
  • In a patch whole lines are marked; the words that changed in a line are marked only where two files are compared.
  • ⌥F3 compares files: it does nothing on a folder, or on a row with no file behind it, such as an entry of the clipboard. Two folders are compared by marking what differs or by synchronizing them.
  • A patch cannot be applied from here.