Function: magit-ediff-stage

magit-ediff-stage is an autoloaded, interactive and byte-compiled function defined in magit-ediff.el.

Signature

(magit-ediff-stage ARG1)

Documentation

Stage and unstage changes to FILE using Ediff.

FILE has to be relative to the top directory of the repository.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-ediff.el
;;;###autoload(autoload 'magit-ediff-stage "magit-ediff" nil t)
(transient-define-suffix magit-ediff-stage (file)
  "Stage and unstage changes to FILE using Ediff.
FILE has to be relative to the top directory of the repository."
  :inapt-if-not #'magit-anything-modified-p
  (interactive
    (let ((files (magit-tracked-files)))
      (list (magit-completing-read "Selectively stage file" files nil t nil nil
                                   (car (member (magit-current-file) files))))))
  (magit-with-toplevel
    (let* ((bufC (magit-ediff--find-file "{worktree}" file))
           ;; Use the same encoding for all three buffers or we
           ;; may end up changing the file in an unintended way.
           (coding-system-for-read
            (buffer-local-value 'buffer-file-coding-system bufC))
           (bufA (magit-ediff--find-file "HEAD" file))
           (bufB (magit-ediff--find-file "{index}" file))
           (lockB (buffer-local-value 'buffer-read-only bufB))
           (modeB (buffer-local-value 'magit-blob-mode bufB)))
      (with-current-buffer bufB
        ;; Make writable and don't shadow self-insert-command.
        (magit-blob-mode -1))
      (magit-ediff-buffers
       bufA bufB bufC nil
       (lambda ()
         (when (buffer-live-p ediff-buffer-B)
           (when lockB
             (with-current-buffer bufB
               (if modeB
                   (magit-blob-mode 1)
                 (setq-local buffer-read-only t)
                 (setq-local read-only-mode--state t))))
           (when (buffer-modified-p ediff-buffer-B)
             (with-current-buffer ediff-buffer-B
               (magit-update-index))))
         (when (and (buffer-live-p ediff-buffer-C)
                    (buffer-modified-p ediff-buffer-C))
           (with-current-buffer ediff-buffer-C
             (when (y-or-n-p (format "Save file %s? " buffer-file-name))
               (save-buffer)))))))))