Live data from Hacker News

Using Git add -p for fun (and profit)

techne98.com

41–50 of 80 posts

Re: Using Git add -p for fun (and profit)

#41
I almost exclusively use add -p. It's another moment to review my changes and it saves me from having to type out the names of the files I've changed. I don't know if I've ever committed a file unintentionally since adopting it.

I like it especially in concert with git commit --amend, which lets me tack my newest changes onto the previous commit. (Though an interactive rebase with fixup is even better)

Re: Using Git add -p for fun (and profit)

#42
post #5

What's wrong with a big end of day commit? Sure, a well crafted git history can be very valuable. But then comes somebody and decides to just flush your well curated history down the toilet (=delete it and start somewhere else from scratch) and then all the valuable metadata stored in the history is lost. Maybe consider putting your energy into a good documentation inside the repository. I would love to have more pro…

> Maybe consider putting your energy into a good documentation inside the repository.

Commit messages are documentation.

If you have a good commit history you don't need write tons of documents explaining each decision. The history will contain everything that you need, including: when and who changed the code, what was the code change and why the code exists. You have a good interface for retrieving that documentation (git log, perhaps with -S, -G, --grep, -L and some pathspecs) without needing to maintain extra infrastructure for that and without being cluttered over time (it will be mostly hidden unless you actively search that). You also don't need to remember to update the documents, you are forced to do that after each commit.

And that's not a hack, Git was made for that.

Re: Using Git add -p for fun (and profit)

#45
My two favourite bits of git add -p that aren't mentioned here:

the / (search) command to search unstaged hunks for a specific keyword rather than having to jump through all the individual changes you've made when there's lots.

and the e (edit) command to manually split out two changes that end up in one hunk that I'd rather have in individual commits.

Re: Using Git add -p for fun (and profit)

#46
post #36

Earlier quoted context omitted.

It hasn't been an issue in my experience at $DAY_JOB, but for us all commits must pass CI and not just the tip of whatever branch was just pushed. So branches with partial commits that fail CI cannot be merged. So if you commit an incorrect partial commit, you either squash it into a commit that does pass CI (usually the next one forward) or you rebase and edit the failed commit and fix it and force push your branch…

If you push a branch with many commits, does it run CI on each commit? In sequence or with some parallelism?

It runs on the last commit with the idea that it will all be squashed at merge. Are you worried about reverting some commits but not all?

Re: Using Git add -p for fun (and profit)

#47

This is the second link from the HN start page that doesn't load due to La Liga censoring in Spain.

Here's a couple archive links that may help you get around that:

https://archive.today/Ig42c (has issues with Cloudflare DNS)

https://web.archive.org/web/20251214151943/https://techne98....

Re: Using Git add -p for fun (and profit)

#48
post #37
post #5

What's wrong with a big end of day commit? Sure, a well crafted git history can be very valuable. But then comes somebody and decides to just flush your well curated history down the toilet (=delete it and start somewhere else from scratch) and then all the valuable metadata stored in the history is lost. Maybe consider putting your energy into a good documentation inside the repository. I would love to have more pro…

For me the point of splitting commit is not for documentation (though it can be an added benefit). It is so that you can easily rollback a feature, or cherry pick, it also makes the use of blame and bisect more natural. Anyways, that's git, it gives you a lot of options, do what you want with them. If a big end-of-day commit is fine for you, great, but some people prefer to work differently. But that's not actually t…

Hmm, this idea of maintaining working copies that differ from upstream strikes me as fragile and cumbersome. For a solo project, sure, whatever works. But for larger projects, IMHO this workflow is an antipattern.

Re: Using Git add -p for fun (and profit)

#49

This is the second link from the HN start page that doesn't load due to La Liga censoring in Spain.

Here's a couple archive links that may help you get around that: https://archive.today/Ig42c (has issues with Cloudflare DNS) https://web.archive.org/web/20251214151943/https://techne98....

I have TOR enabled in my firefox (in a container) just for that. It just seems madness for me (as a non-spaniard) that 2 links of the HN startpage are blocked for football. We are not talking the regular terrorism, abuse/illegal content whatnot. No, censorship to protect football IP.
Post reply on HN