Re:The Art of Manually Editing Hunks
by mananaysiempre on Wednesday November 13, 2024 @01:40PM
(#42128693)
If you were actually editing a patch file, that would be a concern; but in Git, you only edit one hunk at a time, so all’s fine as long as you don‘t mess up the context lines—Git will ignore the source and destination line numbers and counts that your editing has likely rendered incorrect. (An easy way to mess up the context lines is to have your editor strip trailing whitespace on save, as the unified diff syntax for an empty context line is a single space. If anybody asks, in no way did this cause me to be puzzled for literal weeks by hunk edits failing seemingly at random.)
[ Parent
| on HN ]
Re:The Art of Manually Editing Hunks
by rapidlua on Wednesday November 13, 2024 @03:15PM
(#42129486)
I do occasionally attempt to edit patch files produced by git-format-patch. Frequently I end up with corrupt patch. Still curious how to fix those numbers.
Re:The Art of Manually Editing Hunks
by mananaysiempre on Wednesday November 13, 2024 @03:29PM
(#42129636)
With git format-patch I’d say take a worktree, git apply the patch to its intended base, commit, rebase, and git format-patch again :)
Otherwise, well, the numbers are -(old start line number),(old line count) +(new start line number),(new line count) for the entire hunk introduced by @@ (whether it contains one group of changed lines or more). I'm sure you see how to fix them up, but accumulating a line number shift as you go through the file sounds very fiddly and error-prone. It also sounds like something the computer should be able to do for you (given the old patch and the new messed-up patch whose hunks correspond one-to-one to the old).