70 points · by thunderbong · 2y ago · 102 comments
If you use rebase on your own branch, but merge commits on the stable branch (whatever name you use for it), you get both things:
* Small individual commits with the size and ordering that the original author intended on their branch.
* A "commit group" that describes that set of changes for the sake of future maintainers' sanity, and that can be atomically reverted.
More so in PR-based flows. You can have `git log --first-parent` display only the PR merge commits[1], and `git log --no-merges` display the linear history.
[1]: Assuming you actually put useful info on those commits. If you use GitHub, those merge commits can be set to default to PR title and description.
Surely you'd revert to the last good release? I'm sure you could revert a single commit and re-release, but it seems slower (you have to find the right commit to revert, and make sure that the result works correctly) and riskier (since now you're effectively rolling forward to a combination of commits that's never been deployed before)
usually you should err on the side of keeping the commits together, unless you’re close to release, patching a bug in release, etc.
I use `git checkout --patch` mostly when splitting a big commit into smaller commits, retroactively. I start an interactive rebase, chuck 'break' before the big commit, then I start pulling the changes 'forward' from the big commit into the working directory with `git checkout --patch big-commit-hash */path.ext`. Sometimes this works out easier than popping a commit off and re-committing everything seperately, particularly if I already have a commit with a detailed message.
https://github.com/microsoft/vscode/issues/96104
If you staged selected ranges it could change the line endings of the whole file from CRLF to LF. It's very easy to miss since it doesn't show in the normal diff, but then you end up with merge conflicts galore later on.
[alias]
sync = "git squash && git pull --rebase && git pop && git push" # YMMV
Git GUIs are always changing the interface to git. It gives you this weird lockin and islandification. Knowing how to actually use git can give you super powers.Magit's USP is that it's a great interface for those who already use (or are willing to use) `emacs`. `lazygit` is a great interface in its own right.
I use git rebase and git add/reset -p left and right.
I will definitely checkout lazygit though, thank you and others in this HN submission for the mention, looks useful.
But that's the beauty of it: git makes it easy for anyone to use their favourite tool (be it CLI, TUI or GUI) :-).
Something I found that I like about the approach is that sometimes while working on a change, some unrelated code will catch my eye that I want to fix but not as part of my next commit. Being free to make the edit, knowing that I'll see it again later when staging changes, is nice because I would often otherwise forget to go back and revisit the thing I saw. The git add -p sessions then wind up being an opportunity to decide what changes go into each commit, etc. I do burn myself occasionally by having an unrelated edit that is in a hunk that can't be split- I suspect there are tweaks to diff I could make to help with that but have yet to overcome my apathy wrt research.
`git add -p` allows you to "edit [e]" the patch, meaning that you can really decide exactly what should be added. And that's a great opportunity to learn how to manipulate patches, which is an important skill IMO!
https://github.com/tpope/vim-fugitive/blob/master/doc/fugiti...
It's unlikely to remember this feature's existence and benefit from it without habitual usage.
commit.verbose true This adds the whole commit diff in the text editor where you’re writing your commit message, to help you remember what you were doing.
https://jvns.ca/blog/2024/02/16/popular-git-config-options/#...
Regardless I also really like `git add -p`. I don't use it often but it really makes me focus on and consider each hunk. It was the defacto way to do it at an old company I worked at and no, it was not a small startup "hipster" company, we built enterprise ERP software.
(2/5) Stage this hunk [y,n,q,a,d,K,j,J,g,/,e,?]?
Wow, so intuitive! LOL. You really showed him.
This UX is laughably bad. It presents you every hunk, one at a time, without context, and if you want to include some lines and not others, you can't unless all the sub-hunks are exactly one line or you let it launch a text editor and you dick around in the raw diff which is its own domain-specific language.
Why don't people play starcraft like this?
(1/1) Move this zergling [u,d,l,r,b,a,J,g,/,e?]?
The fact that this needs a write-up and discussion is all you need to know. Where is the big how-to for committing partial files in GitHub Desktop? Oh, yeah, nobody needs one because it's obvious and right in front of your face.
If you have no limbs and can't use a mouse to click on things then this UI is great though.
The ‘s’ to split changes is one of my favorite feature.
It takes a few minutes to get used to it, then becomes automatic: add the whole file ‘a’, skip file ‘d’, skip chunk ‘n’, stage chunk ‘y’, split ‘s’, stop here ‘q’, rollback ctrl-c.
The “chunk per chunk” approach is actually really nice, you’re focusing on what exactly you want to get your commit to be about.
You learn it once, that will never change, you’re set for decades.