News for hackers. Stuff that matters.
Re:Julia Evans: Git rebase, what can go wrong by ajkjk on Monday November 06, 2023 @12:14PM (#38165389)
Never understood why you wouldn't want it clean. There's no benefit whatsoever to it being messy and it's a liability for a lot of reasons, whereas the clean version is free and easy and makes everything you do that interacts with git history simpler.
Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @12:33PM (#38165718)
There is a giant benefit to it being messy. And that is that the mess is the actual history.

Every time you do a git rebase, you are literally asking your source control system to lie about history. If you mess up, and you eventually will, you're then forced to manually figure out what the history really was despite being lied to. If you mess it up, well, good luck.

I used to work at a company where someone (we never figured out who) in another group would rebase every few weeks. We didn't find out about it until their stuff was pushed then released. The result was that features which we'd written, QAed, and released to production would simply disappear a few weeks later. With no history suggesting that it ever existed.

Have you ever been pulled off of a project to go fix a project from a month ago which has disappeared from source control? You don't know what happened, you no longer have context, you've just got complaints because your stuff no longer works.

Is your desire for a "clean history" worth potentially creating THAT disaster for other developers on your team???

Re:Julia Evans: Git rebase, what can go wrong by diek on Monday November 06, 2023 @12:47PM (#38165908)
The golden rule is "do not rewrite history of a public branch". Rebase/squash your PR branches to your heart's content, but once it's merged that's it.

You get clean history by not merging branches with 50 intermediary "fiddling with X" commits in them.

Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @12:52PM (#38165988)
Related, it is a bad idea to use long-running per team branches. Merge early, merge often, get commits to trunk ASAP. With best practices on unit testing, code review, and so on, this scales to many thousands of developers. And will save a lot of pain over time.
Re:Julia Evans: Git rebase, what can go wrong by debaserab2 on Monday November 06, 2023 @12:57PM (#38166079)
> I used to work at a company where someone (we never figured out who)

Wouldn't this be trivially solvable by git bisecting your deploy branch?

Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @01:14PM (#38166356)
No, because git bisect operates off of the information in the history. And thanks to the bad rebase, the history no longer existed in the branch.
Re:Julia Evans: Git rebase, what can go wrong by lifeisstillgood on Monday November 06, 2023 @01:31PM (#38166654)
Just clarifying ... they took a version of master from say a month ago, did their work on it, then, they force pushed their work out, wiping everyone else's work that was added to master since one month ago?

I mean that's the equivalent of reversing your JCB through a house on a building site because "the house was not there a week ago when I last moved the JCB".

or am I missing something?

Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @01:40PM (#38166794)
Basically equivalent to that. This was about a decade ago.

We had 4 teams, each released on a schedule. Each team had a branch. When a team released, it was merged from master, then each team pulled. The person who did the pull would change, and it was often a rebase.

So my team released, some other team rebased badly. There would be no sign of problems for us until after they released. But since 2 teams generally released at once, and people didn't remember who actually did the merge a few weeks earlier, it was hard to figure out who was actually messing up. (I had suspicions, but no proof.)

I've seen rebase used appropriately since. But that disaster left scar tissue.

Re:Julia Evans: Git rebase, what can go wrong by lifeisstillgood on Monday November 06, 2023 @01:47PM (#38166910)
So (sorry for picking on this scab) there became 4 branches each of which for the team concerned was the next beautiful branch and then say each week a team woukd merge into master and everyone woukd rebase but fuck that up once and now the beautiful branch team B is working on is out of step with the real master ... oh god.

Yeah that would leave a mark.

Re:Julia Evans: Git rebase, what can go wrong by Chris_Newton on Monday November 06, 2023 @06:39PM (#38170900)
It looks like you’re talking about rewriting history that has already been shared. Pretty much everyone agrees that is a bad idea. It even has a prominent warning in the git book.

What others here, including myself, are advocating is rewriting your own history before you share it, which makes a very different set of trade-offs.

Re:Julia Evans: Git rebase, what can go wrong by latexr on Monday November 06, 2023 @03:09PM (#38168210)
Wasn’t `git reflog` viable?
Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @03:53PM (#38168851)
How do you find the right commit from a month ago to reflog to?

How do you determine which combination of changes are yours, and not accidentally undo changes that other developers made in the last month?

Could git reflog have helped? Maybe sometimes. If we had the foresight to have saved the right commits from the past, sure. I think we did start saving old branches just in case it happened again, but then we had to sort through a month of changes to figure out what to keep, what to change, and what conflicts there might be.

Remember, the person screwing up didn't know he screwed up. And the person trying to fix it is doing so a long time after the fact. It was a disaster.

Re:Julia Evans: Git rebase, what can go wrong by yxhuvud on Monday November 06, 2023 @05:59PM (#38170392)
But that make no sense, as the second someone pulls from that branch it would be noticed.
Re:Julia Evans: Git rebase, what can go wrong by foobarbaz33 on Monday November 06, 2023 @01:14PM (#38166366)
> the mess is the actual history.

The true history is not recorded in your normal commits either. Every time you modify your source buffer, that is the true sequence of events. This truth is lost already as you undo/rework things before you commit. You're ALWAYS manipulating and telling a false story of history whether you realize it or not.

Commits are a tool that give stronger backup/undo protections over simple file saves and in-memory editor undo lists. Just because you happened to save your work in a commit doesn't mean it should be instantly be regarded as holy history. Not anymore so than if you simply saved the file.

I think the bar for "holy" history should be whether it is published to a shared branch.

Re:Julia Evans: Git rebase, what can go wrong by btilly on Monday November 06, 2023 @01:22PM (#38166491)
I believe that you are confusing "full history" and "true history".

Every single point in the commit history represents an actual state of a repository at a specific point of time, along with the information of which point or points were next before it. This is all part of the true history.

This is not a full history - you don't have every keystroke, abandoned commit, switch between branches and so on. But nothing that you're being told is wrong.

As soon as you do a rebase, you're rewriting history. You're claiming that there were specific points of time with specific states that never actually existed. You're losing information about points of time and specific states that actually existed, which someone once considered important enough to do a git commit over.

The difference becomes important if that someone, which at a previous job was me far more often than I would like, tries to go back to the historical commit. And finds that it is gone without a trace.

Re:Julia Evans: Git rebase, what can go wrong by foobarbaz33 on Monday November 06, 2023 @02:31PM (#38167610)
> As soon as you do a rebase, you're rewriting history.

Agreed. But the rewrite occurs in your private branch. It's history is just as private as the undo list in your editor. No one cares about what's going on in your editors undo list. And by the same logic they shouldn't care about commits in a private branch.

> You're losing information about points of time and specific states that actually existed

If you avoid rebase, then you end up "rebasing" without rebasing. You "squash" intermediate states by never recording them to begin with.

Failing to record history is not superior to squashing it.

> And finds that it is gone without a trace.

I don't have the details, but it sounds like someone rebased a public branch. Yes that is bad. But it's sort of like saying we shouldn't drive cars because someone chose to drive the wrong direction down a 1 way road.

Re:Julia Evans: Git rebase, what can go wrong by Nullabillity on Monday November 06, 2023 @04:55PM (#38169587)
> Agreed. But the rewrite occurs in your private branch. It's history is just as private as the undo list in your editor. No one cares about what's going on in your editors undo list. And by the same logic they shouldn't care about commits in a private branch.

The rebase becomes part of the public branch eventually, inflicting your lies on everyone else.

> If you avoid rebase, then you end up "rebasing" without rebasing. You "squash" intermediate states by never recording them to begin with.

If only Git had a third alternative, a way to... entangle two diverging branches of history without destroying or rewriting either. You could say it would be a bit like a car merging into a highway.

> Failing to record history is not superior to squashing it.

"We don't know" is at least an honest statement. Claiming that you do but then making up some nonsense is something that the LLMs do enough of already.

Re:Julia Evans: Git rebase, what can go wrong by foobarbaz33 on Monday November 06, 2023 @07:23PM (#38171332)
I think the crux of the argument is what you think about private git commits. You may think of them as "holy" history. Assuming the commits are still private, I give them no more prestige than the editor's undo log.

What do you think of the editors undo log? It's a very real historical log. Should it be treated as "holy" history too? If not, what makes the undo log less true/important than a private git commit log?

Re:Julia Evans: Git rebase, what can go wrong by Nullabillity on Monday November 06, 2023 @11:33PM (#38173287)
If you did X then Y then Z, there's a difference between saying "I did Y, Z, and X" (squashing/summarizing) and "I did Y then Z then X" (rebasing).

Squashing is often dumb and unhelpful, because you're now re-summarizing the points in time that you already considered worth highlighting when they happened (when you had the most context to judge them!).

Rebasing is lying about the order and/or context that those changes happened in.

Your undo log is comparable to squashing, but not at all to rebasing.

And then again, the first-order vs second-order summarizing distinction matters, and you already capture the second-order summary in your merge commit. Squashing is just destroying information for zero practical benefit.

> private

You keep using that word, but branches are often a lot less private than you think. Push it to get a colleagues' input on something? Congratulations, it's now public. Created a pull request that you want to revise? Already public.

Re:Julia Evans: Git rebase, what can go wrong by tomjakubowski on Tuesday November 07, 2023 @06:43AM (#38175734)
Do you consider it lying when a commit doesn't include all changes in the working tree at the time it was committed? How about when a committer adds a file to .gitignore?
Re:Julia Evans: Git rebase, what can go wrong by dahart on Tuesday November 07, 2023 @10:28AM (#38177894)
My advice is don’t engage with the ‘rebase is a lie’ argument. It is a textbook bad-faith argument, since it deliberately and explicitly ignores the stated intention behind rebase. It’s a talking point that people like to parrot without fully understanding what the author of the argument (Fossil developers) meant, and without fully understanding the implications of the argument. FWIW, HN mods in the past have previously confirmed that repeating this hyperbolic claim goes against HN guidelines.

Fun note though, I argued this directly with Dr Hipp (principal author of SQLite and of Fossil, inventor of the ‘git rebase is a lie’ argument) and during that discussion, he agreed to soften the language on the Fossil pages. They are still hyperbolic, using the word ‘dishonest’, and continue to distort the reasons and usage behind rebase, but he did remove some instances of the word ‘lie’ and ‘lying’, which is progress.

It’s a bit of a shame that they haven’t found the strength to frame Fossil in a positive light without trash-talking the competition. There is a good-faith argument for Fossil vs git, but they’re choosing not to use it.

Re:Julia Evans: Git rebase, what can go wrong by dahart on Monday November 06, 2023 @06:27PM (#38170738)
Git was never intended to capture and preserve the order of git commit commands, and you’re making incorrect assumptions that it was a goal. Maybe the git devs knew there is no useful information and no benefit to being so strict about something so arbitrary, or maybe because forcing people to keep their commits in stone in whatever the first arbitrary way they were added is a big disincentive to making commits at random points in time, which somewhat undermines the point of having a version control system at all.

BTW rebase produces a new commit ordering, but does not modify the old one.

> You’re claiming that there were specific points of time with specific states that never actually existed.

No. You are asserting intent on the part of git users and git that has never existed, you have misunderstood what git history is. The git history is not a claim that the state at that point existed during development, you are projecting your own goals that are not shared by git or git users.

> You're losing information about points of time and specific states that actually existed, which someone once considered important enough to do a git commit over.

Hehe this is so full of assumption. You write it like I’m rebasing someone else’s work, but you already know I’m only rebasing my own commits, and I’m the one who decides what’s important enough to do a commit over.

I like commit early, commit often. I want to make small incremental commits that don’t display to others that way and I expect to put small commits and fix ups together later into a single useful commit with only one commit message.

Re:Julia Evans: Git rebase, what can go wrong by tomjakubowski on Tuesday November 07, 2023 @06:42AM (#38175721)
> Every single point in the commit history represents an actual state of a repository at a specific point of time, along with the information of which point or points were next before it. This is all part of the true history.

Committers always have a choice of which of the changes present in their working tree they stage and then commit. The commit history is always a flat approximation of the real evolution of the files in the repo.

Re:Julia Evans: Git rebase, what can go wrong by Arch-TK on Monday November 06, 2023 @01:21PM (#38166485)
If you think the mess (i.e. 50 mixed up mini commits as you work on a feature and iterate on it) is useful history (it usually isn't) then use a different DVCS because git was not designed around this mode of operation and a lot of its advanced features work poorly when applied to such a history.

Alternative DVCSes which support this workflow include: fossil

Re:Julia Evans: Git rebase, what can go wrong by ajkjk on Monday November 06, 2023 @02:00PM (#38167109)
IMO the relevant 'true history' is at the plane of 'things relevant to other developers'. As far as anyone is concerned, my local work history is that I atomically wrote all my code in a single instant. Commits are that unit of atomicity.

But I have never seen a commit disappear while rebasing, ever. That workflow is busted somehow. They were doing it wrong.

Re:Julia Evans: Git rebase, what can go wrong by dkbrk on Monday November 06, 2023 @04:28PM (#38169273)
> the mess is the actual history.

This argument reminds me of a scene from Yes Prime Minister [0]:

> Humphrey: The minutes do not record everything that was said at a meeting do they?

> Bernard: Well of course not.

> Humphrey: And people change their minds during a meeting don't they?

> Bernard: Well, yes.

> Humphrey: The actual meeting is a mass of ingredients for you to choose from.

> Bernard: Oh, like cooking?

> Humphrey: No, not like cooking. Better not to use that word in connection with books or minutes. You choose, from a jumble of ill-digested ideas, a version which represents the Prime Minister's views, as he would, on reflection, have liked them to emerge.

> Bernard: But if it's not a true record...

> Humphrey: The purpose of minutes is not to record events it is to protect people. You do not take notes if the Prime Minister say something he did not mean to say, particularly if it contradicts something he has said publicly. You try to improve on what has been said, to put it in a better order. You are tactful.

> Bernard: But how do I justify that?

> Humphrey: You are his servant

> Bernard: Oh, yes.

> Humphrey: A minute is a note for the records and a statement of action if any that was agreed upon.

I think the analogy is pretty clear. A pull request does not record every single little change you made when writing it. You choose, from a jumble of ill-digested ideas, a version which better reflects your intent as you would, on reflection, have liked it to emerge. It doesn't matter that it's not a true record, since its purpose is not to record events but to communicate ideas. You try to improve on the commits as they have been written, to put it in a better order. You are tactful.

[0]: https://youtu.be/MF-Qnv2Srfs?si=U6xKNLrTAIn5h1Iz&t=118

Re:Julia Evans: Git rebase, what can go wrong by Nullabillity on Monday November 06, 2023 @04:47PM (#38169491)
You do realize that Yes, Minister is satire...?
Re:Julia Evans: Git rebase, what can go wrong by sethammons on Monday November 06, 2023 @06:45PM (#38170968)
this exact problem led us to block all --force pushes.
Re:Julia Evans: Git rebase, what can go wrong by ajkjk on Tuesday November 07, 2023 @01:28PM (#38180777)
Yeah, that's a standard feature in large organizations afaik.
Re:Julia Evans: Git rebase, what can go wrong by rbehrends on Monday November 06, 2023 @12:23PM (#38165541)
You can have it clean without rebasing. This is simply a matter of properly visualizing the history. Unfortunately, most of the major version control systems have decided to basically just dump a raw graph rather than presenting the history in a more user-friendly fashion.
Re:Julia Evans: Git rebase, what can go wrong by haakonhr on Monday November 06, 2023 @12:17PM (#38165441)
Is it free though?

I'm a fan of rebase myself, but understand the point made above. For me, the biggest pro of a clean history is when doing `git blame`. If the history is clean and the commits are good, it might solve my issue. On the other hand, if the commit in question is a huge mess of unrelated things it doesn't help me at all. I also find it way easier to review a PR with a clean, well-described history.

Re:Julia Evans: Git rebase, what can go wrong by ajkjk on Monday November 06, 2023 @02:03PM (#38167157)
Well I also object to multiple unrelated changes in the same commit. Those should be separate commits, and separate code reviews for that matter.
Re:Julia Evans: Git rebase, what can go wrong by unicornmama on Monday November 06, 2023 @12:37PM (#38165772)
You can run ‘git log —-first-parent’ that will give you the same output as squash merging, without losing the ability to effectively manage stacked branches/PRs.

But because GitHub and other tool’s version of rendering history just flatten merge commits into spaghetti we’re stuck with squash merge. Thanks GitHub.

Re:Julia Evans: Git rebase, what can go wrong by LAC-Tech on Monday November 06, 2023 @03:36PM (#38168607)
I want it clean. But I don't want to do the work to make it clean. The juice is not worth the squeeze.
Re:Julia Evans: Git rebase, what can go wrong by BeetleB on Monday November 06, 2023 @03:56PM (#38168881)
As your parent already said, (and it matches my experience), we didn't have any of these problems when using systems without history rewriting (mercurial, for example).

I recall when I first switched to git at work and the team was insisting on a "linear history", I was bemused: Could these developers really not handle a merge graph? It was bizarre how something straightforward in other VCS is suddenly "messy" amongst git folks.

Re:Julia Evans: Git rebase, what can go wrong by ajkjk on Monday November 06, 2023 @03:58PM (#38168912)
It's not that we/they 'can't' handle it. It's that we choose not to because it's a better life.

It is like moving to one's favorite part of town.

Re:Julia Evans: Git rebase, what can go wrong by BeetleB on Monday November 06, 2023 @04:01PM (#38168942)
> It's not that we/they 'can't' handle it. It's that we choose not to because it's a better life.

As someone who has had to put up with rebase for several years now, my life is definitely not better. And things that were trivial in mercurial are now complicated (seeing the actual chronology - both in the log and in the graph). That graph with multiple branches that git developers find messy can actually be really useful.