Function: magit-discard

magit-discard is an interactive and byte-compiled function defined in magit-apply.el.

Signature

(magit-discard)

Documentation

Remove the change at point.

On a hunk or file with unresolved conflicts prompt which side to keep (while discarding the other). If point is within the text of a side, then keep that side without prompting.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-apply.el
;;;; Discard

(defun magit-discard ()
  "Remove the change at point.

On a hunk or file with unresolved conflicts prompt which side to
keep (while discarding the other).  If point is within the text
of a side, then keep that side without prompting."
  (interactive)
  (when$ (magit-apply--get-selection)
    (pcase (list (magit-diff-type) (magit-diff-scope))
      (`(committed   ,_) (user-error "Cannot discard committed changes"))
      (`(undefined   ,_) (user-error "Cannot discard this change"))
      (`(untracked list) (magit-discard-untracked))
      (`(,_      region) (magit-discard-region $))
      (`(,_        hunk) (magit-discard-hunk   $))
      (`(,_       hunks) (magit-discard-hunks  $))
      (`(,_        file) (magit-discard-file   $))
      (`(,_       files) (magit-discard-files  $))
      (`(,_        list) (magit-discard-files  $)))))