News for hackers. Stuff that matters.
Re:Julia Evans: Git rebase, what can go wrong by watwut on Monday November 06, 2023 @03:18PM (#38168357)
Frankly, people lately spend more time managing commit history then using it. Like, commit history is useful once in a year little bit, maybe, but we spend absurd amount of time trying to make it look nice.
Re:Julia Evans: Git rebase, what can go wrong by gwright on Monday November 06, 2023 @03:29PM (#38168524)
Not my experience, nor my team's experience over almost 10 years of using this approach.
Re:Julia Evans: Git rebase, what can go wrong by Chris_Newton on Monday November 06, 2023 @04:41PM (#38169426)
I’m firmly in your camp on this one, but I’ve noticed that advocating a tidy history gets a lot of push-back online. I think there is an element of self-fulfilling prophecy here. If a team habitually leaves a messy history behind, that history is rarely going to be useful, so naturally the team has low expectations and sees little value in doing anything to curate it. And if a team isn’t used to making an effort to curate its history, they may assume that doing so is expensive because `git rebase -i` is scary and not something they use on auto-pilot for a few seconds at a time.

In other news, our developers also create several small PRs every day but each is for an incomplete change that doesn’t stand alone so we’re never quite sure which features are finished in any given build, everyone keeps complaining about being interrupted to do code reviews all the time when the code reviews have no value anyway because they always just say LGTM :+1:, and we have targets that no more than 15% of commits should break production when CI/CD deploys them and that we recover fully within an hour each time that happens. If only there were something we could do to improve all this…

Re:Julia Evans: Git rebase, what can go wrong by watwut on Monday November 06, 2023 @05:06PM (#38169736)
I worked in a team where tech lead insisted on nice history. It was a lot of effort all the time and very little to no benefit.

He was lead and could influence salaries, his opinion mattered. So, in real life, people rarely pushed back. That is not the same as us sharing the same opinions tho. I became more verbal about history not being useful online.

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @05:21PM (#38169929)
If a strategy requires humans to be virtuous AND vigilant it is doomed to failure.

I rarely use history and prefer merge/squash, with automated CI tools, and tests. "Why" is kept in doc strings, comments, specs, and story tickets. Everything viewable in gitlab with automatic links. All this gets out of the critical path, every day.

I submit that, if your code is so complex that diagnosing a bug is a major research project rather than moving forward with a few extra/modified lines of obvious fix, then that is the problem to focus on.

Re:Julia Evans: Git rebase, what can go wrong by Chris_Newton on Monday November 06, 2023 @06:08PM (#38170507)
If a strategy requires humans to be virtuous AND vigilant it is doomed to failure.

Sorry, but I don’t buy that. By the same principle, there’s also no point in writing unit tests or defining static types or having code reviews, all of which require thought and extra work, yet can yield considerable dividends when done even moderately well.

I rarely use history and prefer merge/squash, with automated CI tools, and tests. "Why" is kept in doc strings, comments, specs, and story tickets.

The argument for a tidy history isn’t just about a different place to explain a change. It’s about presenting work in clearly defined, meaningful steps to other readers like code reviewers, or perhaps someone who found these commits later through `git blame` on a problematic line of code or `git bisect` after a regression. It’s about each commit representing a complete, self-contained change that could later be reverted, or cherry-picked or merged to another branch.

I submit that, if your code is so complex that diagnosing a bug is a major research project rather than moving forward with a few extra/modified lines of obvious fix, then that is the problem to focus on.

Some problems have a lot of essential complexity. The code to solve them necessarily has at least the same degree of complexity. Sooner or later, there will probably be a change to that code with an unintended consequence for something else. Keeping the code and its history tidy and systematic is, IMHO, how you avoid those investigations becoming major research projects.

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @10:18PM (#38172794)
One of these things is not like the other. (Journey vs. final destination.)

As an industry we get paid primarily for 1) working software and 2) communicating with stakeholders.

Tidy yet inaccessible (to non-dev) construction stories are not on that path. I would argue unit tests et al are, to ensure #1.

No stakeholders? Put why into a readme, where it can be seen at a glance.

Complexity must be broken down into bite-sized chunks for a solution to be feasible in the first place, reliable in the second. i.e. skull-size limits. If there’s any code I don’t understand I rewrite it until I can. With tests of course.

Re:Julia Evans: Git rebase, what can go wrong by Chris_Newton on Tuesday November 07, 2023 @05:10AM (#38175138)
Sorry again, but I’m still not seeing the distinction I think you’re trying to make here.

I see version history as an asset, just like the code itself, tests, developer documentation, the bug tracker database… None of these things are directly visible to end users under normal circumstances, but they are useful sources of information and organisation and collaboration that help developers to create the software that users do see.

To me, a repo with a messy version history is like code full of superficial comments, a test suite with high coverage metrics that still doesn’t exercise the most important functionality, a dev team where the only documentation is some auto-generated static site that reproduces what any decent IDE would show in real time anyway, or a tracker where all the tickets are vague one-liners. You can produce useful software despite those things, but why would you?

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Tuesday November 07, 2023 @06:36PM (#38184659)
It's not a black and white distinction, I agree.

Also, I said/meant stakeholders not end-users. Ours definitely do write bugs, look at docs and generate db reports etc.

The main distinction is that things on that list have a high cost-to-benefit ratio to goals 1 & 2, where history maintenance does not. The cost is high and utilization isn't. Additionally it can't be used to communicate with anyone but developers.

Re:Julia Evans: Git rebase, what can go wrong by watwut on Tuesday November 07, 2023 @06:22AM (#38175557)
> there’s also no point in writing unit tests or defining static types or having code reviews

Not true. I do not do those to have nice clean process. I do unit tests, because without them the code is unstable and it is hard to fix bugs without causing unrelated ones. If the code is super simple and unlikely to break, I don't do test. I like to use static types, because I am much faster when writing them. The code is more readable and I have less bugs. Now, I have seen both useless and useful code reviews.

But, in all of those cases, things are done because they beneficial impact in final code and speed of delivery. Beautiful git history does not have such tangible measurable benefit. Git blame and bissect work without it, you just need one more step once in a while.

Re:Julia Evans: Git rebase, what can go wrong by Chris_Newton on Tuesday November 07, 2023 @07:48AM (#38176154)
But, in all of those cases, things are done because they beneficial impact in final code and speed of delivery. Beautiful git history does not have such tangible measurable benefit.

I respectfully disagree. In my experience, a tidy history directly benefits both efficiency and outcomes of code reviews, speeds up investigations of both bug reports and sometimes general background before starting new development, makes development much easier in situations where changes may need to be isolated and deployed to specific environments (not all software is a web app using CI/CD…), makes it much easier to back out a problematic change without causing unnecessary collateral damage, and helps to verify which development has actually been completed and deployed to which stages/environments, which can be useful for general awareness around the team but is particularly important if you’re operating in any kind of regulated field. All of that in exchange for usually spending less time in `git rebase -i` than it’s taken me to write this comment seems like a bargain to me, but YMMV.

Re:Julia Evans: Git rebase, what can go wrong by seba_dos1 on Wednesday November 08, 2023 @08:38AM (#38190106)
Fully agreed. Seems to me that most people who don't care about curating their commits (and either leave a mess or squash everything at merge regardless of context) simply don't work on projects that are either complex, distributed or long-living enough, so they can easily afford such carelessness.
Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Wednesday November 08, 2023 @05:18PM (#38197947)
Nope, ~15 year project here. No one is reading obsolete commit messages when there are hundreds of files to get familiar with today.

Not to mention quality is significantly higher now so you wouldn't want to refer to a granular history of crap anyway. Any time spent on that would have been completely wasted as I wipe out a thousand line file for a new one with a hundred lines because requests hadn't been invented yet and the original implementer didn't understand network protocols or how to use argparse and implemented it from scratch poorly.

Re:Julia Evans: Git rebase, what can go wrong by seba_dos1 on Thursday November 09, 2023 @12:08AM (#38201387)
Yeah, as I suspected.

If you can afford your first instinct to be reimplementing things from scratch, your understanding of the value provided by proper version control will be limited. Some of us work with constantly changing code developed by thousands of people from all around the world in projects that 15 years ago were migrating to git and that have tons of downstreams, and are thankful for maintainers and processes that keep the commit graph useful.

Though that said, once you're comfortable enough with git you'll be thanking yourself for commit hygiene even when coming back to your few years old single-person codebases.

In my experience, developer's work consists mostly of gaining understanding of codebases. It's like being a detective. Writing new code happens too, but not as often and it's not as impactful (and usually can and should be handled by less experienced devs). The most impactful things are single line changes that took a week to write, or a few dozen lines that took months. Rewriting existing code from scratch is something that happens only as a last resort and after very careful consideration. Maintaining some basic version control hygiene makes a whole world of difference in such work. Sure, you can live without it, but you can also live without docs, comments or tests (and sometimes have to - which makes you appreciate them when they're there).

Re:Julia Evans: Git rebase, what can go wrong by seba_dos1 on Monday November 06, 2023 @08:14PM (#38171792)
> I think there is an element of self-fulfilling prophecy here.

This too, but there's another thing at play as well: many developers don't know git at all. They just memorized enough commands to let them do their work. They don't understand what they're doing, so they can't reap the benefits of the tool they use. You won't get much use of RAW photos if all you can do in a graphics editor is clicking "auto enhance" button.

Re:Julia Evans: Git rebase, what can go wrong by nilptr on Monday November 06, 2023 @03:57PM (#38168890)
I use commit history a little bit more than that, but mostly agree. I had another dev recently give me crap about the mess of "WIP" commits on a feature branch because they review by clicking through the commits and my commits don't tell much of a useful story other than I apparently did some shit and eventually it all worked.

That said, I've also come to the conclusion there's basically two classes of Git users: people who really understand Git and use it fully, and those of us who basically use it as a place to shove source code before quitting for the night.

Re:Julia Evans: Git rebase, what can go wrong by Terr_ on Monday November 06, 2023 @04:43PM (#38169441)
> Frankly, people lately spend more time managing commit history then using it.

At one company with a Giant Custom Enterprise App, I ended up occasionally acting as a historian for pieces of the company with bad communication/institutional-memory, ex: "Oh, the +5% Foo charge was because of a request 3 years ago by vice-president X, here's the ticket number, before that it used to be +3%."

In those circumstances--where the implementation is the source of truth for business process--a well-maintained stream of commit-messages become quite useful.

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @05:28PM (#38170010)
Comment with a ticket-id would be more efficient.
Re:Julia Evans: Git rebase, what can go wrong by Izkata on Monday November 06, 2023 @07:04PM (#38171155)
On a long-lived codebase you're going to end up with nearly as many such comments as there are lines of code. Now that's a cluttered mess.
Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @09:22PM (#38172387)
When/how to comment is an art in itself, in no conflict to what I wrote.
Re:Julia Evans: Git rebase, what can go wrong by Terr_ on Tuesday November 07, 2023 @01:04AM (#38173741)
While it's often said that comments should capture the "why" of code, I don't usually think that ought to extend to "cuz ticket#" except when that ticket number is an significant bug/limitation that explains a nasty hack.

Noting each feature ticket that ever affected a line--or even just at the function level--is sort of like maintaining a few thousand incomplete micro-changelogs. Doing it "acceptably well" takes much more effort than grooming the commit history so that someone can click "show change history for selected lines" in their IDE.

Plus consider all the unnecessary noise it makes for people reading the code, or reviewing a PR.

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Tuesday November 07, 2023 @06:28PM (#38184585)
No, it's not difficult (cut/paste), nor a burden for reading in comments or docstrings. Could be measured in seconds instead of hours massaging history.

Also, you seem to be under the misconception history doesn't exist because it wasn't massaged, which is false.

Re:Julia Evans: Git rebase, what can go wrong by Izkata on Tuesday November 07, 2023 @08:25PM (#38185570)
And the commit message is an amazing place to put that.
Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Wednesday November 08, 2023 @05:15PM (#38197914)
Not if you want them read by non-developers.
Re:Julia Evans: Git rebase, what can go wrong by Izkata on Thursday November 09, 2023 @06:42PM (#38212981)
Why would you have non-developers reading code?
Re:Julia Evans: Git rebase, what can go wrong by m000 on Monday November 06, 2023 @04:50PM (#38169523)
Curating the commit history takes like 10' per PR and can easily repay in hours of work when some bug hits. Or when you want to tell the junior that wants to implement X for A, why don't you take a look on this one commit where we implement X for B?
Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @05:32PM (#38170049)
Is there something wrong with the latest version of the method? Instead of one from ~18 months ago which may not work any longer?
Re:Julia Evans: Git rebase, what can go wrong by m000 on Monday November 06, 2023 @06:05PM (#38170475)
I'm not sure I get you. What do you mean the "latest version of the method"? And why shouldn't code from 18 months ago not work? Some minimal regression testing should be in place for production code, and it is probably also used regularly.

So, yes seeing e.g. how "CSV export for class A" is implemented is a great guide for implementing "CSV export for class B".

Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Monday November 06, 2023 @09:43PM (#38172539)
Most recent. Interfaces change over time.

Everything you need is in the most recent copy. Showing an old one invites difficulty for no benefit.

Re:Julia Evans: Git rebase, what can go wrong by deredede on Tuesday November 07, 2023 @01:40AM (#38173908)
A commit is not a method, it is a change set potentially affecting many files. Pointing people to the commit used to implement feature A lets them understand the whole story of which components need to change (and how) to implement similar feature B in a way that pointing them to a single method or file doesn't necessarily can.
Re:Julia Evans: Git rebase, what can go wrong by watwut on Tuesday November 07, 2023 @05:07PM (#38183655)
The idea is for junior to learn from massive commit that affected many files?
Re:Julia Evans: Git rebase, what can go wrong by mixmastamyk on Tuesday November 07, 2023 @06:13PM (#38184422)
This reply is overstating a bit, but it does sound like a lot of work simply to avoid saying, "here look at these methods in this file" and the unstated, and trace the imports yourself.

Not to mention just finding the right commit months later sounds like more work than that already.

Personally, even if I were to make the history absolutely perfect, I never get the code right (interfaces etc), the first time. It might be hours or days before I'm 98% happy with the final implementation. Sometimes big refactor opportunities come to me days or months later, e.g. where I move code needed multiple times into a more central mixin location.

Re:Julia Evans: Git rebase, what can go wrong by erik_seaberg on Monday November 06, 2023 @05:49PM (#38170270)
If I can invest business hours and get back minutes during an outage at 3 AM, I should do that.
Re:Julia Evans: Git rebase, what can go wrong by krferriter on Wednesday November 08, 2023 @11:15AM (#38192524)
Yeah I just don't care really. I have noisy dev branches, force pushing rebases from an upstream branch, and usually just squash merge and throw the history away when merging back to master. I've never come across a situation where I needed a preserved, fine-grained commit history for every dev branch after they've already been put in working order and merged to master. I guess I just don't use commit histories very much after the fact, like months later trying to find what original commit changeset a line of code was changed in. It's never mattered.
Re:Julia Evans: Git rebase, what can go wrong by funcDropShadow on Friday November 10, 2023 @05:19AM (#38217149)
I use the commit history every time a I open file I haven't worked on for a while. Just seeing the output of git annotate in the border of Intellij gives me a sense how old code is, what changed together with what and whom to ask in case of questions.