from Hacker News

The Art of Manually Editing Hunks

by alraj on 11/6/24, 6:20 AM with 18 comments

  • by qazxcvbnm on 11/14/24, 1:34 AM

    Sounds like a problem for rediff (https://github.com/twaugh/patchutils).

    Instead of directly editing the unified diff file, make a copy and edit the copy. Once you’re done, call rediff original-patch edited-patch to get a patchfile with fixed offsets.

    Note that rediff only fixes your offsets, and doesn’t remove empty hunks. patch is not happy about empty hunks existing, so if you happen to revert all changes in a hunk, remember to delete the hunk after rediff. Probably this ought to be contributed back upstream.

  • by lionelw on 11/14/24, 9:43 AM

    If this is about staging partial file changes, then I think this is where git GUIs especially excel. It's typically a matter of selecting and deselecting individual lines of change. The concept and term "hunk" (to mean a group of lines, and honestly "chunk" would've been a better choice) never shows up. Pretty intuitive and foolproof.

    I've used Git Cola on Linux and Github Desktop on Windows. Both free.

  • by ris on 11/13/24, 10:06 PM

    Further to this, don't underestimate how powerful git diff | sed | git apply can be for mass edits of files.
  • by impure on 11/13/24, 5:57 PM

    Yeah, you can do this to make your commits cleaner, but I find it easier to just manually edit the file and then undo after you add the patch.
  • by rapidlua on 11/13/24, 6:20 PM

    Is it just me, or the piece doesn’t explain how to make edits without messing up the hunk?
  • by Optimal_Persona on 11/13/24, 6:14 PM

    I honestly thought this would be about retouching photos of buff men!