Splitting a hunk with magit

EmacsMagit

Emacs Problem Overview


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?

Emacs Solutions


Solution 1 - Emacs

You can set the mark correctly with Ctrl+Space (C-SPC) and magit will only commit the selected portion.

Solution 2 - Emacs

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.

Solution 3 - Emacs

Magit reuse diff-mode but don't expose many of diff-mode commands in its magit-revision-mode as this does VC package.

For example you can call diff-split-hunk which is usually C-c C-s in diff-mode.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondeepakgView Question on Stackoverflow
Solution 1 - EmacsDominik HonnefView Answer on Stackoverflow
Solution 2 - EmacsphilsView Answer on Stackoverflow
Solution 3 - EmacsgavenkoaView Answer on Stackoverflow