2022 Developer Survey is open! Take survey.

Hot answers tagged

29 votes
Accepted

Magit diff side by side

The Emacs package for doing this is named Ediff and Magit supports Ediff. To get started press e on the change for which you want to see the side-by-side comparison. You might also have to use E ...
user avatar
  • 24.2k
11 votes

Use magit to display the difference between two branches

I think that the command you're looking for is magit-diff-range. Being on some branch, hit M-x and magit-diff-range. Then, when prompted, enter the name of the other branch and you will get a buffer ...
user avatar
11 votes
Accepted

How to diff one file against another branch with Magit

Invoke the magit-diff transient (d). Limit to the file you are interested in with the -- option. (Hit tab for completion.) Ignore white space changes with the -w option. Call the magit-diff-range ...
user avatar
  • 6,384
6 votes

How can I diff two long lines from the same buffer?

Split the window. In each window, put point at the start of one of the two lines (or at the start of each "..." in your example). M-x compare-windows RET C-xzzzz... to repeatedly compare as many times ...
user avatar
  • 43.1k
5 votes
Accepted

How to diff a single, unstaged file in magit-status?

Type TAB. Many sections in Magit can be expanded (and then again collapsed) by pressing TAB. Actually I was working on adding indicators to make that more obvious yesterday. Might try to finish that ...
user avatar
  • 24.2k
5 votes
Accepted

Is there a way to revert only certain lines from a diff hunk?

Magit can do this by limiting the revert action to the region. With the built-in diff-mode you can get the same kind of effect by splitting the hunk into portions using diff-split-hunk which is bound ...
user avatar
  • 4,079
4 votes

How do I check if two regions have identical content?

(As previous mentioned in the comments by glucas), a heavyweight approach to comparing regions is provided by the excellent ediff library: ediff-regions-linewise ediff-regions-wordwise These ...
user avatar
  • 43.1k
4 votes

How do I check if two regions have identical content?

Interactively, I do this one of a few ways, depending on the scenario. First, if the regions are small -- e.g., lately I've been comparing some test output with the expected results, and both are ...
user avatar
4 votes
Accepted

view git diff version by version

I think commands magit-log-buffer-file and its variant magit-log-buffer-file-popup are what you are looking for. These are bound to l and L in Magit buffers, respectively. Invoking the former command ...
user avatar
  • 11.3k
4 votes
Accepted

Make Emacs diff files before asking to save

I've used a function like this for something similar: (defun current-buffer-matches-file-p () "Return t if the current buffer is identical to its associated file." (autoload 'diff-no-select "diff"...
user avatar
  • 19.1k
4 votes
Accepted

How to activate diff-mode from command line?

Command line arguments are processed in-order. So your -f diff-mode will put into diff-mode whichever buffer happens to be current right after Emacs has started (most likely it will be the *scratch* ...
user avatar
  • 25.2k
3 votes
Accepted

Find the first difference between two buffers

Why a binary search? compare-buffer-substrings returns the number of chars that were equal. So you can just do: (goto-char (+ (point-min) -1 (abs (compare-buffer-substrings ...
user avatar
  • 25.2k
3 votes
Accepted

Diff of two buffers without creating temporary files

@tmalsburg, Following command calls diff on 2 buffers without the creation of temporary files. It uses named pipes as you suggested above: (require 'diff) (defun diff-buffers-without-temp-files (...
user avatar
  • 380
3 votes

how to properly capture `diff` output in buffer (without first opening a file)?

You can always write a function to do all the repeated steps for you. This should get you started: (defun diff-generic(command) (interactive "sDiff command:") (let ((buffer (generate-new-buffer "*...
user avatar
  • 131
3 votes

Lightweight (pure elisp) diffs?

I don't think there is an existing Elisp solution for that. But if you look at how I implemented smerge-refine-subst (also used in diff-refine-hunk) it should give you some idea of how you can play ...
user avatar
  • 25.2k
3 votes

How do I check if two regions have identical content?

Since this solution uses only CLI Diff, it also answers your "ignore whitespace" question, tweak diff's option to do whatever you want. Please man diff. ;; Diff two regions ;; Step 1: Select a region ...
user avatar
  • 4,581
3 votes
Accepted

How to open a diff at the position of the current buffer?

Edit: this is now a package: diff-at-point This solution parses the diff hunks to lookup a buffer location in the diff. By default, if the current location isn't part of the diff, the closest line ...
user avatar
  • 7,069
3 votes
Accepted

Org Mode evaluate diff code block

You can make your own execute function for diff blocks. #+BEGIN_SRC emacs-lisp (defun org-babel-execute:diff (body params) (with-temp-buffer (insert body "\n") (shell-command-on-...
user avatar
  • 10.9k
3 votes
Accepted

What can I use instead of `diff-buffers` in Aquamacs?

diff-buffers is a new command in Emacs 27.1. Do you really want to see the diff output, rather than compare the buffers? Emacs has a nice built-in interface to compare two files: Ediff. (Note that ...
user avatar
2 votes
Accepted

how to properly capture `diff` output in buffer (without first opening a file)?

Try M-! <your diff command/> C-x b *Shell Command Output* (where the output of M-!==M-x shell-command goes by default) M-x diff-mode
user avatar
2 votes

Automatically show diff before saving file

What about something like this? #+BEGIN_SRC emacs-lisp (defun my-diff () (let ((temp-file (make-temp-file "gpgdiff-")) (contents (buffer-string)) (current-file (buffer-file-name))) (...
user avatar
  • 10.9k
2 votes

Ignoring newline changes in smerge-diff-mine-other

Indeed, all those diff options work line-by-line, and insertion/removal of newlines creates completely different lines so they don't see those changes as "just whitespace". You need to use a word-...
user avatar
  • 25.2k
2 votes
Accepted

vdiff-refine-all-hunks/ediff-update-diffs in startup eval

vdiff processes the output of diff asynchronously which takes a nonzero amount of time. Instead of guessing when to run vdiff-refine-all-hunks just set vdiff-auto-refine to t to let vdiff run it at ...
user avatar
  • 1,490
2 votes
Accepted

How can I use magit to diff some text with my clipboard?

Step 1: Select text and M-x diff-region-tag-selected-as-a Step 2, Select or not select text, M-x diff-region-tag-selected-as-b You need install cli tool diff on windows (its bundled with Cygwin or ...
user avatar
  • 4,581
2 votes

Magit diff side by side

Using Emacs and Magit on Windows, I didn't find it intuitive to get side by side diffs (with 2 windows instead of 3) even with the above answer. Adding this in case it helps others. Here's what I ...
user avatar
  • 121
2 votes

Magit magit-diff-refine-hunk does not work if I don't move the cursor to the good lines

That's because you are not using custom-set-variables correctly. You are not supposed to write that by hand, but if you wrote it like this (custom-set-variables '(magit-diff-refine-hunk (quote all))) ...
user avatar
  • 24.2k
2 votes

Use magit to display the difference between two branches

Git diff doesn't work for me as it can't find kdiff. I don't know why git diff would need kdiff (whatever that is), but if git diff does not work on the command line, the various magit-diff-* ...
user avatar
  • 24.2k
2 votes

How to open a diff at the position of the current buffer?

Edit, I've since written made a version of this which parses the diff hunks, here. Posting own answer, it works but it has some limitations. This is a wrapper for vc-root-diff which opens a ...
user avatar
  • 7,069
2 votes

Show only different symbols. Not entire line

You apparently used dired-diff. Please just provide the recipe as part of your question. Don't throw a (very hard to read) screenshot at us. The behavior of the command depends on your OS diff ...
user avatar
  • 69.2k

Only top scored, non community-wiki answers of a minimum length are eligible