There's a question on SO about splitting hunks using magit, and the two solutions given are to either stage the region (mark a region, hit stage), or to shrink/grow all hunks using +
& -
. That's not what I'm after.
In magit's status buffer, I want to split a hunk into two hunks, at the point, or at least at the lines around the point.
Turning this (excuse my bad diff formatting)
@@ blah blah blah
- foo
+ bar
+ baz
+
Into
@@ blah blah
- foo
+ bar
@ blah blah
+ baz
When the point is on bar.
Motivations:
baz
being a debug statement, so I'd like to drop it from the commit offoo
&bar
without getting rid of it.bar
andbaz
being only partially related, meaning that their changes should not be in the same commit.bar
is large andbaz
is small, making it a lot easier to split the hunk rather than selectbar
Similar to the last point, say a 20 line commit contains a single line the middle that should not be staged. It'd be easier to split & stage the top and bottom two hunks ignoring the middle one than use the region.
The above can arise sometimes when the diff presentation will separate the before and after of something that's been modified, and have something unhelpful in the middle. e.g.
@@ line
- old_foo
+ random stuff
+ new foo
diff-split-hunk
which does just that. IOW your request is for a way to usediff-split-hunk
(or something equivalent) from the magit-status buffer.