Staging patches with git add (2024)
simonholywell.com
Staging patches with git add (2024)
1–10 of 54 posts
Re: Staging patches with git add (2024)
#2I 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)
#3IntelliJ has that since 2018, with visual change-by-change checkboxes that should go into each commit, very handy.
Re: Staging patches with git add (2024)
#4I find splitting hunks a pain. I wish I could just split by line, would be a great feature.
Re: Staging patches with git add (2024)
#5Super useful, and easy to do in the VS Code merge pane.
Re: Staging patches with git add (2024)
#6In the case of a newly committed file you can add just the file with
git add . -N
And then review the text itself as part of the git add -p workflow
Re: Staging patches with git add (2024)
#7I find splitting hunks a pain. I wish I could just split by line, would be a great feature.
I've used tig for longer than I can remember for my selective staging needs.
Re: Staging patches with git add (2024)
#8Vin fugitives difftool is even better
Also, you can use -p for stash push
Re: Staging patches with git add (2024)
#9I 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.
Re: Staging patches with git add (2024)
#10I 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.