Live data from Hacker News

Staging patches with git add (2024)

simonholywell.com

21–30 of 54 posts

Re: Staging patches with git add (2024)

#22

Magit allows selective staging/unstaging, either of hunks, or by selecting lines (AKA Emacs's "region"). I avoid staging from the git commandline, unless I'm just doing whole files. PS: Majutsu provides this too (a magit-like tool for jj)

Neogit, Magit inspired, does the same for Neovim. Would recommend!

Re: Staging patches with git add (2024)

#24

My biggest problem with `add -p` is correcting any patches I added or rejected by accident. Often times I skip through dozens of things I don’t want to add, then realized that last hunk was something I did need. But I can’t re-visit it, I have to start over and try extra hard to not skip past it again. I wish the j and k shortcuts could revisit hunks I’ve already added/rejected, not just ones I haven’t reviewed yet.…

From skimming through the article, isn't that what the uppercase variants do?

Re: Staging patches with git add (2024)

#25

Magit allows selective staging/unstaging, either of hunks, or by selecting lines (AKA Emacs's "region"). I avoid staging from the git commandline, unless I'm just doing whole files. PS: Majutsu provides this too (a magit-like tool for jj)

Neogit, Magit inspired, does the same for Neovim. Would recommend!

I think you can do the same with tig and lazyvim. Sometimes you just need interactivity.

Re: Staging patches with git add (2024)

#27

My biggest problem with `add -p` is correcting any patches I added or rejected by accident. Often times I skip through dozens of things I don’t want to add, then realized that last hunk was something I did need. But I can’t re-visit it, I have to start over and try extra hard to not skip past it again. I wish the j and k shortcuts could revisit hunks I’ve already added/rejected, not just ones I haven’t reviewed yet.…

From the article, try J and K instead of j and k; that moves to next/previous hunk, not next/previous unreviewed hunk.

Re: Staging patches with git add (2024)

#28
post #14

> If you’re not already using git add -p to stage your commits then you’re missing out. After switching to jujutsu, I assure you I don't miss this feature. jj takes the opposite approach. It keeps staging things, and you use split whenever you want to separate things out. (And yes, it stores the staged changes as revisions, so you can always back out to a previous staged state).

> jj takes the opposite approach. It keeps staging things, and you use split whenever you want to separate things out.

You can use `git reset -p` to selectively unstage hunks the same way if you wanted to.

Re: Staging patches with git add (2024)

#29

Magit allows selective staging/unstaging, either of hunks, or by selecting lines (AKA Emacs's "region"). I avoid staging from the git commandline, unless I'm just doing whole files. PS: Majutsu provides this too (a magit-like tool for jj)

VSCode also allows staging/unstaging specific hunks by hovering over the hunk near the left/right separator in diff view - super handy when I need it!

Re: Staging patches with git add (2024)

#30

Magit allows selective staging/unstaging, either of hunks, or by selecting lines (AKA Emacs's "region"). I avoid staging from the git commandline, unless I'm just doing whole files. PS: Majutsu provides this too (a magit-like tool for jj)

The per-line staging in magit is a frequent tool I use. I can be in the middle of bunch of other changes, change 1 line for a different reason that would otherwise be "mid-hunk", and the stage & commit it with its own explanation.

It releases me from having to have the "discipline" to stay 100% focused on the broader task at hand and say "hmm, I should fix that while I'm here", without co-mingling purposefully different commits.

Truly fantastic. Absurdly, I have no idea how to do this on the command line, though presumably it is possible from there too (just a lot, lot less convenient).

Post reply on HN