Live data from Hacker News

Staging patches with git add (2024)

simonholywell.com

1–10 of 54 posts

Re: Staging patches with git add (2024)

#2
I find grepdiff and this function are pretty useful if you want to pull certain hunks out of a large change set:

    #!/bin/bash
    
    # Put this into your .bashrc, or whatever.
    function git-add-regex {
      git diff -U0 | grepdiff -E "$1" --output-matching=hunk | git apply --cached --unidiff-zero
    }
https://gist.github.com/smuuf/76bde33d65b3dbbc2411e8519f3e6c...

Re: Staging patches with git add (2024)

#10
post #9
post #4

I find splitting hunks a pain. I wish I could just split by line, would be a great feature.

Use 'e' in -p mode and you can edit the hunks as you wish, choose lines, etc.

The whole "Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?" line is pretty intimidating, but I urge anyone who still wants to understand git and be able to (themselves) use it effectively, to do "?" when you see it, read through what each action does and forcefully try them out to see what they do, in some low stakes project. Ends up being a super quick way of staging a whole bunch of work and avoiding staging other, but it's pretty weird at first glance.
Post reply on HN