Problem with diff-split-hunk (vc-mode)

Hello there good people!

Maybe someone here can help me figure it out this behavior.

If I visit a git controlled file, and add a few new lines.

C-x v = will take me to the vc-diff buffer. Let’s say I want to split my hunk into 2. I can navigate to the line where it is and use C-c C-s (diff-split-hunk) to split it.

From there, I can always kill (k) the first one and C-x v v add a message and C-c C-c to apply/commit. But the contrary is never true. I mean, if I kill the second split, something is broken and my patch fails to apply.

Do I need to fix something with diff markings? Do I have to add some blank new lines? Does anybody have a cool workaround to this?

It seems such a killer built-in feature not to use it.

PS.: My memory might be failing, maybe it is the first one that always applies and the second one never, but this is it.

1 Like

Not much help here, I don’t think I’ve seen this problem. Maybe I’m always choosing the “correct” hunk to commit (?)… usually I do this when I want to keep part of the diff and revert the rest, but, like I said, I don’t do that very often. You’ll have to post back here if you find a solution. Now I’m tempted to go try it out on a junk repo…

And so I did. I created a new directory, added file.txt and filled it with the text of the cpio man page. Added several additional lines of text in different places, ran C-x v = on the file, then C-c Cs on an arbitrary line, used k to kill the other hunks, then used C-x v v to commit the remaining one. It always worked regardless of which hunk I chose to keep and commit. Maybe its something else in your work flow? I did not try having multiple hunks, splitting one of them, removing the part I didn’t want to keep and then committing all the remaining hunks.