Function: magit-file-delete

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

Signature

(magit-file-delete FILES &optional FORCE)

Documentation

Delete the selected FILES or one file read in the minibuffer.

With a prefix argument FORCE do so even when the files have uncommitted changes. When the files aren't being tracked in Git, then fallback to using delete-file.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260822.1158/magit-files.el
;;;###autoload
(defun magit-file-delete (files &optional force)
  "Delete the selected FILES or one file read in the minibuffer.

With a prefix argument FORCE do so even when the files have
uncommitted changes.  When the files aren't being tracked in
Git, then fallback to using `delete-file'."
  (interactive (list (if-let ((files (magit-region-values 'file t)))
                         (magit-confirm-files 'delete files "Delete")
                       (list (magit-read-file "Delete file" nil t)))
                     current-prefix-arg))
  (let ((args (and force (list "--force"))))
    (when-let ((dirs (seq-filter #'file-directory-p files)))
      (if (yes-or-no-p (format "Recursively delete %s %S:"
                               (if (length= dirs 1) "directory" "directories")
                               (string-join dirs ",")))
          (push "-r" args)
        (user-error "Abort")))
    (if (magit-file-tracked-p (car files))
        (magit-call-git "rm" args "--" files)
      (let ((topdir (magit-toplevel)))
        (dolist (file files)
          (setq file (expand-file-name file topdir))
          (if (file-directory-p file)
              (delete-directory file t t)
            (delete-file file t))))))
  (magit-refresh))