22

I know how to get to a diff from an older commit: get to *magit-log*, and "click" on the commit. How to get a particular change in the diff applied in reverse? I want it to just modify the file (and buffer, if open).

lukstafi
  • 1,825
  • 14
  • 22

2 Answers2

32

I was going to offer a way to do it in vc mode, but this question caused me to discover exactly what you want(I think)

Move your point to the change you want to revert and type v (magit-revert-item)

If you then go to magit-status window you will see that there is an unstaged change with the reverse of the change.

That's way easier than the vc-mode way which is to C-c C-r (diff-reverse-direction) and then C-c C-a (diff-apply-hunk).

Either one is pretty darned handy IMO

Tom Willis
  • 5,138
  • 20
  • 34
  • 3
    And like other magit functions, you can do this for just the marked region if necessary. You may or may not need to ensure point is *inside* the region (this at least used to be necessary for staging or unstaging regions). `C-x C-x` if you marked it the 'wrong' way around. – phils Nov 05 '13 at 23:07
  • 2
    lukstafi: `C-h m` `C-s revert` ? – phils Nov 05 '13 at 23:09
  • I believe this should be a capital `V`? More specifically `V v` as described at https://magit.vc/manual/magit/Reverting.html? – Supernormal Sep 27 '19 at 11:32
  • @Supernormal in the magit rev mode which you get to from magit log the shortcuts now are `_` and then theres a bunch of options but the relevant one here is `o` for revert hunk and `O` for revert commit. when you hit `?` in that mode there's not option for `v` or `V` on the version i'm looking at it is spacemacs though so perhaps `v` and `V` are overridden to keep visual mode working. I think the true answer is use `?` :) – Tom Willis Sep 27 '19 at 13:09
0

Go to the hunk you want to undo and hit C-u C-c C-a.

Stefan
  • 26,706
  • 4
  • 42
  • 75