Next: , Up: Comparing-Diffing-Merging   [Index]


8.15.1 Diff Mode

Used for the output of ‘M-x diff’. Select Diff mode manually with ‘M-x diff-mode’.

Function: diff OLD NEW &optional SWITCHES NO-ASYNC (interactive)

Find and display the differences between OLD and NEW files. Read new and old using the minibuffer when called interactively (defaults are current buffer’s file name and its backup file, respectively). If called interactively with a prefix argument, prompt for diff switches. Otherwise the swiches found in the variable diff-switches are passed.

Hunks

The changes specified in a patch are grouped into “hunks”, which are contiguous chunks of text that contain one or more changed lines. Each hunk is preceded by a “hunk header”, which specifies the old and new line numbers where the hunk’s changes occur. Diff mode highlights each hunk header

File Header

The first hunk in a patch is preceded by a file header, which shows the names of the new and the old versions of the file, and their time stamps.

Editing Hunks

M-n’ ‘(diff-hunk-next)’

Move to the next hunk-start (‘diff-hunk-next’). With prefix argument N, move forward to the Nth next hunk.

M-p’ ‘(diff-hunk-prev)’

Move to the previous hunk-start (‘diff-hunk-prev’). With prefix argument N, move back to the Nth previous hunk.

M-}’ ‘(diff-file-next)’

Move to the next file-start, in a multi-file patch (‘diff-file-next’). With prefix argument N, move forward to the start of the Nth next file.

M-{’ ‘(diff-file-pref)’

Move to the previous file-start, in a multi-file patch (‘diff-file-prev’). With prefix argument N, move back to the start of the Nth previous file.

M-k’ ‘(diff-hunk-kill)’

Kill the hunk at point (‘diff-hunk-kill’).

M-K’ ‘(diff-file-kill)’

In a multi-file patch, kill the current file part. (‘diff-file-kill’).

C-c C-a’ ‘(diff-apply-hunk)’

Apply this hunk to its target file (‘diff-apply-hunk’). With a prefix argument of ‘C-u’, revert this hunk, i.e. apply the reverse of the hunk, which changes the “new” version into the “old” version.

C-c C-b’ ‘(diff-refine-hunk)’

Highlight the changes of the hunk at point with a finer granularity (‘diff-refine-hunk’). This allows you to see exactly which parts of each changed line were actually changed.

C-c C-c’ ‘(diff-goto-source)’

Go to the source file and line corresponding to this hunk (‘diff-goto-source’). By default, this jumps to the “new” version of the file, the one shown first on the file header. With a prefix argument, jump to the “old” version instead.

C-c C-e’ ‘(diff-ediff-patch)’

Start an Ediff session with the patch (‘diff-ediff-patch’). See (ediff)Top

C-c C-n’ ‘(diff-restrict-view)’

Restrict the view to the current hunk (‘diff-restrict-view’). *Note (emacs)Narrowing. With a prefix argument, restrict the view to the current file of a multiple-file patch. To widen again, use ‘C-x n w’ (‘widen’).

C-c C-d’ ‘(diff-unified->context)’

Convert the entire buffer to the “context diff format” (‘diff-unified->context’). With a prefix argument, convert only the hunks within the region.

C-c C-u’ ‘(diff-context->unified)’

Convert the entire buffer to unified diff format (‘diff-context->unified’). With a prefix argument, convert unified format to context format. When the mark is active, convert only the hunks within the region.

C-c C-w’ ‘(diff-ignore-whitespace-hunk)’

Re-generate the current hunk, disregarding changes in whitespace (‘diff-ignore-whitespace-hunk’).

C-x 4 A’ ‘(diff-add-change-log-entries-other-window)’

Generate a ChangeLog entry, like ‘C-x 4 a’ does (*note (emacs)Change%20Log), for each one of the hunks.


Next: eDiff Mode, Up: Comparing-Diffing-Merging   [Index]