Live data from Hacker News

How to commit part of file in Git

newbeelearn.com

81–90 of 104 posts

Re: How to commit part of file in Git

#81
post #79

Earlier quoted context omitted.

It’s really easy to learn: one of the option is ‘?’, try it out, it will give you more explanation. 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 exa…

It's really easy to learn how to use a slot machine too. Or dwarf fortress. It's not productive -- it's a hobby at best. EDIT: You have extremely low standards for what constitutes a professional tool these days. You also didn't address my point. split is brain damaged and doesn't work: + assertEquals(byte[].class, p.get0().getClass()); + assertEquals(String.class, p.get1().getClass()); You try to split this hunk and…

It’s a professional tool not a hobby, I don’t understand the analogy. Learning to use -p makes you more productive.

Re: How to commit part of file in Git

#83

Splitting up commits is totally underrated and seen rarely. I see colleagues over and over again plumbing 4 kinds of changes into the same commit. Good luck reverting the one change that caused an outage.

> Good luck reverting the one change that caused an outage.

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)

Re: How to commit part of file in Git

#84

VSCode handles this very well too: select the lines you want to commit and do "Git: Stage selected ranges"

I'd be careful with that feature though because it used to have an absolutely awful bug (and it might still tbh, I haven't had it confirmed that it's fully fixed yet). 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…

That should only be a problem in windows.

Re: How to commit part of file in Git

#85
I have used patch-adding almost exclusively for a few years. It really helps me stay aware of my workspace and avoid committing temporary tweaks. I can also keep semi-permanent personal tweaks uncommitted in my workspace and get constant reminders if I still have an inline debugging flag activated.

It's unlikely to remember this feature's existence and benefit from it without habitual usage.

Re: How to commit part of file in Git

#86

Splitting up commits is totally underrated and seen rarely. I see colleagues over and over again plumbing 4 kinds of changes into the same commit. Good luck reverting the one change that caused an outage.

And on this topic, another underrated feature that everyone seems to hate is merge commits. 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' san…

I also set up recently the policy to only use merge commits on stable branch, as otherwise the path filter^1 in the workflows would not detect correctly which files changed after merging a PR.

[1] https://github.com/dorny/paths-filter

Re: How to commit part of file in Git

#87
post #51
post #26

Earlier quoted context omitted.

Sounds reasonable. Also, when squashing a PR would conflate unrelated commits then maybe those commits should have been separate PRs instead. I've recently started to like squashing after usually preferring rebase merges, because with squashes I have an easy option to rewrite the commit message and edit out all of those meaningless "fix typo", "improve" and "now actually working" lines...

> I've recently started to like squashing after usually preferring rebase merges, because with squashes I have an easy option to rewrite the commit message And why couldn't you rewrite the commit messages while rebasing? EDIT: oh, you mean from the GitHub webUI, I presume. Got it.

> EDIT: oh, you mean from the GitHub webUI, I presume. Got it.

Yes, exactly, while reviewing and merging other peoples PRs. Technically I could still rewrite in other ways, but while squashing in the web UI was the most comfortable workflow.

Re: How to commit part of file in Git

#90

This article should mention `lazygit`. That's one of the best ways to customize hunks without committing to `emacs`. 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.

+1 for lazygit, and I say this as someone who has used git exclusively on the cli for years and still continues to do so. It's just that lazygit makes staging hunks, squashing and rebasing such a joy.
Post reply on HN