28

Is there a way to issue the command:

git checkout NameOfFile

on a modified and unstaged file from within MAGIT?

  • 3
    You can press k to kill the changes when point is on the same line with the unstaged file. – Tu Do May 26 '15 at 16:34
  • Try x when hovering a hunk in spacemacs. – moritzschaefer Oct 12 '18 at 13:20
  • @moritzschaefer There is no indication that this question applies to spacemacs. – DoMiNeLa10 Oct 19 '18 at 16:39
35

You can use one of the below to discard changes in unstaged files:

  • M-x magit-revert-item (bound to v in magit-status-mode)
  • M-x magit-discard-item (bound to k in magit-status-mode) - works on staged items too

Using either method will ask you to confirm before discarding.

  • 1
    You can also use k which is bound to magit-discard-item in magit-mode. – Kaushal Modi May 26 '15 at 16:35
  • Yes, that works too. – Manuel Uberti May 26 '15 at 16:36
  • Tried using both methods, however I still receive the message: "Nothing to discard here". – user2522280 Jun 12 '15 at 15:55
  • thanks! Magit-mode seems like the best way to do just about everything I've found... – Jimmy Hoffa Apr 9 '16 at 16:32
  • @user2522280 Have you saved your file? git status should give you information that the file has been modified. – DoMiNeLa10 Oct 19 '18 at 16:40
14

Reversing, reverting and discarding are distinct actions. Together with staging and unstaging, they are referred to as "apply variants".

To discard a change means to throw it away. Only un-committed changes can be discarded. When a staged change is discarded it is not only removed from the index (that is known as unstaging), but also from the work tree.

To reverse a change means to apply it to the work tree in reverse. Both committed and merely staged changes can be reversed. (Reversing staged changes is actually useful, i.e. when splitting up a commit).

Only commits can be reverted, in other regards it's similar to reversing.

See https://github.com/magit/magit/wiki/History-Manipulation for details.

  • "Reverting staged changes..." - you meant "Reversing staged changes..." I guess – npostavs May 27 '15 at 13:41
  • Yes. Common mistake because this distinction is not as clear as the other :-) – tarsius May 27 '15 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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