Staging patches with git add (2024)
simonholywell.com
simonholywell.com
PS: Majutsu provides this too (a magit-like tool for jj)
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).
git add . -N
And then review the text itself as part of the git add -p workflow
git add --intent-to-add .
git diff
git add -p .
## To then reset and keep changes
## these are equivalent:
# git reset .
# git reset --mixed .I wish the j and k shortcuts could revisit hunks I’ve already added/rejected, not just ones I haven’t reviewed yet. On a large set of unstaged changes that you mostly don’t want, it really sucks to “lose your place” in the list of hunks.
D’oh. I should have reviewed the docs better, you’re totally right. Now I feel dumb. Wish I would’ve learned this a long time ago. (Or maybe I did and forgot, perhaps multiple times. I’ve used git basically daily since 2006. I’ve forgotten a lot.)
Sublime Merge for the win; a fantastic visual interface with context and reversible inputs. Don't leave home without it!
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).
If LLM coding assistance continues to increase, it's going to be a rather large speed bump to cross
One of the biggest problems is actually unsolvable if you want to keep colocated Git and git tooling around, because it has to do with how jj fundamentally works: detached HEADs, detached HEADs everywhere
You yourself may not use AI, this is for those who do and are interested in switching to jj
OK, OK - I lie. For personal projects I do - some handle jj decently well. But at work I don't let it make any commits ... and it never tries to.
What tools are you using that won't work with detached heads?
I know WHY detached heads happen when using jj (from git's perspective); that doesn't mean I have to LIKE it. Why can't interim worktree commits just use the most-recent bookmark, which is 99% of the time what you'd likely want anyway, is easily movable if it's not, and keeps all Git tooling (as well as old Git users like me) from getting confused?
I've been letting LLMs make commits for many months now. Perhaps that's the "problem" in my case, and why LLMs' incomplete "mental" model of jj seems to cause issues. You wouldn't see the problem if you are still manually committing. (Also, WHY are you still manually committing? LLMs are pretty great now at git committing, at least!)
Fix the command line. Mine just shows the git hash, and the color is only red if there's an uncommitted diff. It doesn't care if I'm in a detached head.
> Also, WHY are you still manually committing? LLMs are pretty great now at git committing, at least!)
I like to control the shape of my commit log.
You can use `git reset -p` to selectively unstage hunks the same way if you wanted to.
Whereas with jujutsu, after learning it once, I never looked up `split`.
And it's not like I use `split` often. I can go weeks without it.
Easier to just use jujutsu. It has a lot of benefits than just this.
I do think that as nice as jj is, the git add -p and git rebase -i are both still tools that base jj could do much better on, that people rightfully are going to miss & feel absolutely stranded, bereft, alone for when they are not there. They are just very clear. There's other tools in jj ecosystem you can build back up by (jj-hunk for example) but the Great Filter of dev ambition to keep striving on just to get back to the core git basics is deeply winnowing.
Can you elaborate? I don't know any reason I would prefer `git rebase -i` over jujutsu. Do you have an example?
(Ditto for `git add -p`)
I don't need cli tools. It's basically a spreadsheet of history that can be directly modified, specified.
git commit -m "WIP" & git revert HEAD & git revert HEAD & git reset HEAD^
Now I've got a copy of the changes as a commit and I'm my work tree. I widdle it down until its one change only. Then I do:
git commit -m "Bla" & git rebase -i HEAD~3 -X theirs
Them order Bla above WIP. I keep doing this "double revert" trick until the WIP no longer applies. Then done.
#!/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...Also, you can use -p for stash push
Sometimes I think the use cases for “version control I use locally on my machine” and “version control that goes up to the public repo and is reviewed” are so wildly different, it’s a wonder we even use the same tool for both.