Previous: , Up: Visiting Files and Blobs   [Contents][Index]


5.8.2 Visiting Files and Blobs from a Diff

These commands can only be used when point is inside a diff.

RET (magit-diff-visit-file)

This command visits the appropriate version of the file that the diff at point is about.

This commands visits the worktree version of the appropriate file. The location of point inside the diff determines which file is being visited. The visited version depends on what changes the diff is about.

  1. If the diff shows uncommitted changes (i.e., staged or unstaged changes), then visit the file in the working tree (i.e., the same "real" file that find-file would visit. In all other cases visit a "blob" (i.e., the version of a file as stored in some commit).
  2. If point is on a removed line, then visit the blob for the first parent of the commit that removed that line, i.e., the last commit where that line still exists.
  3. If point is on an added or context line, then visit the blob that adds that line, or if the diff shows from more than a single commit, then visit the blob from the last of these commits.

In the file-visiting buffer this command goes to the line that corresponds to the line that point is on in the diff.

The buffer is displayed in the selected window. With a prefix argument the buffer is displayed in another window instead.

User Option: magit-diff-visit-previous-blob

This option controls whether magit-diff-visit-file may visit the previous blob. When this is t (the default) and point is on a removed line in a diff for a committed change, then magit-diff-visit-file visits the blob from the last revision which still had that line.

Currently this is only supported for committed changes, for staged and unstaged changes magit-diff-visit-file always visits the file in the working tree.

C-<return> (magit-diff-visit-file-worktree)

This command visits the worktree version of the appropriate file. The location of point inside the diff determines which file is being visited. Unlike magit-diff-visit-file it always visits the "real" file in the working tree, i.e the "current version" of the file.

In the file-visiting buffer this command goes to the line that corresponds to the line that point is on in the diff. Lines that were added or removed in the working tree, the index and other commits in between are automatically accounted for.

The buffer is displayed in the selected window. With a prefix argument the buffer is displayed in another window instead.

Variants of the above two commands exist that instead visit the file in another window or in another frame. If you prefer such behavior, then you may want to change the above key bindings, but note that the above commands also use another window when invoked with a prefix argument.

Command: magit-diff-visit-file-other-window
Command: magit-diff-visit-file-other-frame
Command: magit-diff-visit-worktree-file-other-window
Command: magit-diff-visit-worktree-file-other-frame

Previous: General-Purpose Visit Commands, Up: Visiting Files and Blobs   [Contents][Index]