How does one ediff a current file--ie working tree--against an arbitrary version in some previous commit?
In this case, I'm interested in pulling in some, but not all, changes from a commit in another feature branch that was rejected.
I can't think of a one-step way to do this. The best I can come up with is
Type dr (magit-diff
), and set the range to the commit
If point is on the commit, you can copy it with C-w before calling dr.
In the diff buffer, go to the file you want and hit e
(magit-ediff-dwim
)
Though you might consider doing away with the ediff step. You can hit v to reverse a hunk at point in the working tree.
C-x l
from the magit-diff
transient state to enable the -R
option that reverses old and new, so that you get the diff in the order you want if you're pulling in changes selectively.
Commented
Aug 30, 2023 at 14:53
I am answering here because I could not find any existing answer on SO or StackExchange that solved this exact problem, but I just figured out one solution.
There are a few steps involved, but this is without custom elisp.
It depends on which buffer you're going to achieve this from, so I'll give an example of doing it from the magit-log
or magit-refs
buffer (i.e., instead of from a file buffer):
Optionally place point at the revision you want to diff your working tree against, then d
(Diff), C-u
(universal arg), w
(Diff worktree) and enter a revision (default is revision at point). This will diff the entire tree and place you in a magit-diff
buffer, so you can either (A) Navigate to the Magit section of the file you're interested in, or (B) Place point on one of the file paths in the first section and press e
(Ediff dwim) to open an Ediff session against the file revision and the writable version of your working copy. This is the big differentiator you and I are after -- being able to pull hunks into the writable buffer visiting the working file (not being stymied by a readonly buffer populated with the blob from HEAD
revision).
If you don't want to diff the entire tree, then you need to use --
(Limit to files) in the Magit Diff transient.
HTH!