Function: magit-diff-visit-file
magit-diff-visit-file is an interactive and byte-compiled function
defined in magit-diff.el.
Signature
(magit-diff-visit-file &optional OTHER-WINDOW)
Documentation
From a diff, visit the appropriate version of the file at point.
Display the buffer in the selected window. With a prefix argument, OTHER-WINDOW, instead display the buffer in another window.
In the visited file or blob, go to the location corresponding to the location in the diff.
If point is on an added or context line, visit the blob corresponding to our side (i.e., the new/right side). If point is on a removed line, visit the blob corresponding to their side (i.e., the old/left side).
This applies to diffs of staged and unstaged changes as well. For
staged changes the two sides are blobs from the index and the HEAD
commit. For unstaged changes the two sides are the actual file in
the worktree and the blob from the index.
To visit the file in the worktree, regardless of what the current diff
is about, use C-j (magit-diff-visit-worktree-file) (magit-diff-visit-worktree-file).
In the past \<return> (this command) used to go to the file in the
worktree, if point is on an added or context line of a diff showing
staged changes. Set magit-diff-visit-prefer-worktree to t to restore
that behavior, but note that doing so makes the behavior inconsistent
and you would give up on the ability to visit the index blob. If you
already use C-j (magit-diff-visit-worktree-file) to jump to the live file from committed changes,
it might be better to retrain muscle memory to do the same from staged
changes.
This command only works when point is inside a diff; elsewhere use
magit-find-file.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-diff.el
;;;; Visit Commands
;;;;; Dwim Variants
(defun magit-diff-visit-file (&optional other-window)
"From a diff, visit the appropriate version of the file at point.
Display the buffer in the selected window. With a prefix argument,
OTHER-WINDOW, instead display the buffer in another window.
In the visited file or blob, go to the location corresponding to the
location in the diff.
If point is on an added or context line, visit the blob corresponding
to our side (i.e., the new/right side). If point is on a removed line,
visit the blob corresponding to their side (i.e., the old/left side).
This applies to diffs of staged and unstaged changes as well. For
staged changes the two sides are blobs from the index and the `HEAD'
commit. For unstaged changes the two sides are the actual file in
the worktree and the blob from the index.
To visit the file in the worktree, regardless of what the current diff
is about, use \
\\<magit-diff-section-map>\
\\[magit-diff-visit-worktree-file] \
(`magit-diff-visit-worktree-file').
In the past \\`<return>' (this command) used to go to the file in the
worktree, if point is on an added or context line of a diff showing
staged changes. Set `magit-diff-visit-prefer-worktree' to t to restore
that behavior, but note that doing so makes the behavior inconsistent
and you would give up on the ability to visit the index blob. If you
already use \\[magit-diff-visit-worktree-file] to jump to the live \
file from committed changes,
it might be better to retrain muscle memory to do the same from staged
changes.
This command only works when point is inside a diff; elsewhere use
`magit-find-file'."
(interactive "P")
(magit-diff-visit-file--internal
(and magit-diff-visit-prefer-worktree
(memq (magit-diff--dwim) '(staged unstaged)))
(and other-window t)))