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:
bazbeing a debug statement, so I'd like to drop it from the commit offoo&barwithout getting rid of it.barandbazbeing only partially related, meaning that their changes should not be in the same commit.baris large andbazis small, making it a lot easier to split the hunk rather than selectbarSimilar 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