I cannot stage a hunk with magit-stage in any *magit-diff buffer except the *magit-diff buffer created via status buffer. Magit says "user-error: Cannot stage committed changes".

I mean, I cannot stage a hunk in a *magit-diff buffer created from

  1. M-x magit-diff-dwim in a source file
  2. M-x magit-diff-popup then d in a source file
  3. M-x magit-diff neither in a source file nor in a *magit buffer

However, I can stage a hunk in a *magit-diff buffer created from

  1. M-x magit-diff-dwim in a *magit buffer
  2. d then d in a *magit buffer

I found this because I often want to diff my editing file and I felt that magit-status and d d is a bit tedious and wanted to by-pass magit-status. What am I missing?

I'm using magit 2.11.0-236-g1c69e9e9.

1 Answer 1


When you stage a change, then you tell Git to take what is currently in a file in the working tree and put it in the index (also known as the staging are), so that you can later create a new commit from that.

Obviously you cannot stage a change that is already staged. It is also not possible to stage a change that is already committed. While it might be technically possible in some cases that a change that lives on another branch applies to the index cleanly and can therefore be applied to the index directly, that's not really what staging means and Magit disallows it to avoid user mistakes.

So the question becomes How to show the unstaged changes without going through the status buffer?

In all first 1 through 3 you end up calling magit-diff eventually, whose purpose is to show you the differences between two commits - not the unstaged changes.

Maybe magit-diff-dwim should instead display the unstaged changes when invoked from a file buffer, but that will have to be investigated.

Currently you have to use M-x magit-diff-unstaged or C-c M-g D u to show the unstaged changes directly from a file buffer. The latter requires that you have enabled magit-file-mode (do so by enabling global-magit-file-mode).

  • Thanks! I somehow thought that magit-diff calls git diff without any arg, even though it asks me which commit I want to diff against. Just for the test I patched magit-diff-dwim to call magit-diff-unstaged for the default case and works like a charm. I don't diff two commits while I'm editing my source code but do git diff a lot. So, if by any chance, magit-diff-dwim is changed to call magit-diff-unchanged would be nice. git diff without any arg does show you unchanged diff and if you wan to see staged diff, you need --cached. Nov 21, 2017 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.