Skip to main content
18 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 ...
Fernando Jascovich's user avatar
18 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 ...
Kyle Meyer's user avatar
  • 7,274
10 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 ...
phils's user avatar
  • 55k
6 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 ...
rpluim's user avatar
  • 5,695
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 ...
tarsius's user avatar
  • 26.8k
5 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-...
John Kitchin's user avatar
  • 12.2k
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* ...
Stefan's user avatar
  • 27k
4 votes
Accepted

Is there an Emacs function or package to visually compare two text strings?

Based on the answer above by @db48x, this seems to roughly work: (defun malb/visual-diff-strings (old-string new-string) (let ((old-buffer (get-buffer-create (make-temp-name "old-buffer-"))...
Martin R. Albrecht's user avatar
3 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))) ...
tarsius's user avatar
  • 26.8k
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 ...
Stefan's user avatar
  • 27k
3 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-* commands ...
tarsius's user avatar
  • 26.8k
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 in ...
ideasman42's user avatar
  • 9,513
3 votes
Accepted

Why does vdiff not show differences between these two files?

Mine works just fine, though I've recently installed it from melpa and it's marked as version "0.2.4" maybe try upgrading your package, remove your modifications, or make sure that M-x vdiff-...
C11g's user avatar
  • 343
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 ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

Save diff from Magit

There is a different command, magit-patch, for this. The command only works in a Magit Diff buffer. So, you have to do: magit-diff-unstaged (C-c d) or similar command to create a "Magit Diff&...
Yasushi Shoji's user avatar
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 ...
ideasman42's user avatar
  • 9,513
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 ...
Nerdtron's user avatar
  • 121
2 votes
Accepted

How to make a diff tool ignore asterisks?

One can configure ediff-filtered-filters such that it replaces multiple leading stars with one leading star and call ediff-buffers. The following Elisp function my-org-ediff does that for you. Just ...
Tobias's user avatar
  • 34.1k
2 votes

How to make a diff tool ignore asterisks?

You can do an ediff-buffers-wordwise and type #h \*+ to ignore words consisting of stars. If you advance to the next diff by pressing SPC ediff will skip words only differing in the number of stars....
Tobias's user avatar
  • 34.1k
2 votes

How to make a diff tool ignore asterisks?

If you are content to use diff on the bash command line and are not looking for a pure emacs solution, you can use process substitution to pass into diff slightly modified files: diff <(sed -E 's/^...
NickD's user avatar
  • 36.2k
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 ...
Drew's user avatar
  • 80.9k
2 votes

How to apply a hunk of changes in diff to current branch?

Put the cursor on the change in question and press a for "apply". Also see Staging and Unstaging and Applying in the manual.
tarsius's user avatar
  • 26.8k
2 votes
Accepted

How to efficiently merge 2 buffers which are partially overlapping?

You don't need to do anything fancy with ediff or keyboard macros. Just concatenate the two files together, then remove any duplicates. You can do that at the command line: cat a b | sort | uniq > ...
db48x's user avatar
  • 20k
2 votes

Org Mode evaluate diff code block

Another implementation, possibly shorter. Does not require elisp. #+NAME: diff #+BEGIN_SRC bash :var a="foo.txt" b="bar.txt" :results verbatim :wrap src diff diff -u $a $b patch -s ...
mankoff's user avatar
  • 4,386
2 votes

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

You are using Emacs version 24, but the online manual is for Emacs 27. You either need to upgrade, or to read the Emacs manual that came with your copy of Emacs. Type C-h i to open the info viewer, ...
db48x's user avatar
  • 20k
2 votes

How can I run a function when vc-diff finishes?

A quick look seems to indicate that the only way you can do it is by advising vc-diff-finish: it seems to be called after an async diff is done, so you should be able to piggyback whatever you want to ...
NickD's user avatar
  • 36.2k
2 votes
Accepted

save-some-buffers diff prevents scrolling

The *Diff* buffer can be scrolled up and down respectively with C-M-v and C-S-M-v. If you scroll it past its end, it will be removed from view. Alternatively, set enable-recursive-minibuffers to t, ...
rpluim's user avatar
  • 5,695
1 vote
Accepted

How to diff against a git branch?

This can be done using: (vc-root-version-diff nil "master" nil) The first nil could be replaced by (vc-root-dir). The second one could be replaced by HEAD however this doesn't include local changes ...
ideasman42's user avatar
  • 9,513

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