Function: magit-diff-buffer-file

magit-diff-buffer-file is an autoloaded, interactive and byte-compiled function defined in magit-diff.el.

Signature

(magit-diff-buffer-file &optional UNSTAGED-ONLY)

Documentation

Show diff for the blob or file visited in the current buffer.

Limit the diff to the file or blob.

When the buffer visits a blob, then show the respective commit. When the buffer visits a file, then show the differences between HEAD and the working tree, or the index with a prefix argument.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260822.1158/magit-diff.el
;;;###autoload
(defun magit-diff-buffer-file (&optional unstaged-only)
  "Show diff for the blob or file visited in the current buffer.

Limit the diff to the file or blob.

When the buffer visits a blob, then show the respective commit.
When the buffer visits a file, then show the differences between
`HEAD' and the working tree, or the index with a prefix argument."
  (interactive (list current-prefix-arg))
  (require 'magit)
  (if-let ((file (magit-file-relative-name)))
      (if magit-buffer-revision
          (magit-show-commit magit-buffer-revision
                             (car (magit-show-commit--arguments))
                             (list file))
        (save-buffer)
        (let ((line (line-number-at-pos))
              (col (current-column)))
          (with-current-buffer
              (magit-diff-setup-buffer (and (not unstaged-only)
                                            (or (magit-get-current-branch)
                                                "HEAD"))
                                       nil
                                       (car (magit-diff-arguments))
                                       (list file)
                                       'unstaged
                                       magit-diff-buffer-file-locked)
            (magit-diff--goto-file-position file line col))))
    (user-error "Buffer isn't visiting a file")))