Is there a way to issue the command:
git checkout NameOfFile
on a modified and unstaged file from within MAGIT?
Is there a way to issue the command:
git checkout NameOfFile
on a modified and unstaged file from within MAGIT?
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 tooUsing either method will ask you to confirm before discarding.
k
which is bound to magit-discard-item
in magit-mode
.
– Kaushal Modi
May 26 '15 at 16:35
git status
should give you information that the file has been modified.
–
Oct 19 '18 at 16:40
k
on Unstage changes (<n>)
(where k
and v
also work on local changes inside a file! You can thus reverse some changes and keep the others in the same file. Magit rocks \o/
– kotchwane
May 29 '20 at 08:21
M-x magit-revert-item
only worked for staged changes, whereas M-x magit-discard-item
allowed me to discard changes in un-staged items
– PeterT
Sep 20 '22 at 16:16
magit-discard
and magit-revert
.
– Christian Herenz
Dec 09 '22 at 12:54
k
works.
– Stand with Gaza
Sep 23 '23 at 14:37
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.
k
to kill the changes when point is on the same line with the unstaged file. – Tu Do May 26 '15 at 16:34x
when hovering a hunk in spacemacs. – moritzschaefer Oct 12 '18 at 13:20