I have 2 edits very close by (and therefore part of the same hunk), that I'd like to commit separately. Is it possible to split a hunk from within magit?
3 Answers
You can set the mark correctly with Ctrl+Space (C-SPC) and magit will only commit the selected portion.
5 Comments
phils
I always set the mark at the bottom of the region, and move point to the top in order to stage or unstage regions, as I've had issues (which I can't recall the specifics of) doing it the other way around in the past. YMMV.
phils
Re: my previous comment, I recently read the reason for this, which is that when you un/stage the region, point must be within the region you are acting on. You can, of course, use
C-x C-x to exchange point and mark if you had done it the other way around.Dominik Honnef
Does it behave differently when using transient-mark-mode? Because I always select top to bottom and never had a problem.
Vebjorn Ljosa
It wasn't enough for me to set the mark (
C-SPC). I had to press C-SPC a second time to activate transient-mark-mode.jfs
to be clear: magit will only commit whatever is selected. It doesn't matter how did you select e.g., I use
Shift + <arrows> to select portion of a hunk and press s to stage the selected part.You can also use - and + to decrease or increase the extent of the hunks in the diff (and 0 resets), but dominikh's answer is the most important one to know about.
3 Comments
Mike H-R
This does not work for me, has this been removed in the newer version of magit or is this something peculiar to my setup?
phils
Mike H-R: assuming you're in the magit-status buffer, then this should still work AFAIK.
Mike H-R
Yes, I was mistaken, you need to press + or - on the line starting
@@ (the hunk information line) rather than inside the hunk as I had been trying to.