Live data from Hacker News

How to Squash and Rebase in Git

jenweber.dev

51–59 of 59 posts

Re: How to Squash and Rebase in Git

#51
post #33

Amazing that we don't yet have a source control solution that's simpler than git. It should not be a barrier to entry for our profession.

If a person dislikes Git then the best they can do now is to use another VCS locally and only interface with Git remotely. Although they might be forced to use a lot of Git features if their boss wants people to actively rebase their own pull requests.

Re: How to Squash and Rebase in Git

#52

For ardour, we almost never squash commits because we prefer our (always linear) git history to show the actually "story" of a branch's development. There are two exceptions. 1. branch developer suffered from several "thinkos" along the way, the branch doesn't contain that many changes, and there's simply no benefit to seeing the contrast between the initial (mistaken) changes and the final result. 2. the branch comm…

You have no way of knowing if a developer squashed locally...

Re: How to Squash and Rebase in Git

#53

Earlier quoted context omitted.

> If I get a PR to review I want the set of commits to be clean and represent logical changes. No “oops” commits. +100. Though every time this comes up on HN you would be surprised by how much some people just vehemently disagree. I will also add another requirement - all unit tests should pass at each commit in the PR. That way, you can use the rebase strategy to merge and you would still be able to bisect.

Passing unit tests on each commit is only a realistic goal if developers can run all tests locally in less than (say) an hour. If the test suite is ten hours and you have ten commits on a branch then it quickly becomes silly to bog down your build servers (or cloud bills) with building and testing the intermediate commits over 90h. Using your own machine to do it (blocking it from doing other work) is obviously not a…

> If the test suite is ten hours and you have ten commits on a branch then it quickly becomes silly to bog down your build servers

That's a fair point, but I would say that if you encourage your devs to make each commit logical, meaningful and self contained, this is worth the extra cost.

Also, you don't need to run ALL unit tests - just the ones affected by commit you are testing. This of course requires a build system with good dependency analysis.

Re: How to Squash and Rebase in Git

#54

For ardour, we almost never squash commits because we prefer our (always linear) git history to show the actually "story" of a branch's development. There are two exceptions. 1. branch developer suffered from several "thinkos" along the way, the branch doesn't contain that many changes, and there's simply no benefit to seeing the contrast between the initial (mistaken) changes and the final result. 2. the branch comm…

Did you every see the commit history of someone trying to fix their Azure DevOps pipeline?

Re: How to Squash and Rebase in Git

#55
post #15

About half the time I get stuck during squashing and rebasing I end up trashing everything, re-cloning the repo and just doing one commit with all my changes from the other branch. Much easier than trying to figure out what series of errors or issues git is having. Fundamentally, this is my fault - I don’t have a good mental model of git, and even when I do have a solid understanding of what I’m attempting to achieve…

'git reflog' is your friend as it keeps a history of local operations, then you can do a 'git reset --hard HEAD@{X}' where X is the point in your reflog before the rebase started.

While this is true, it's also more of a crutch. You should practice to predict, before your rebase, what conflicts your are gonna hit. And aborting a rebase is a significantly safer option. I would only recommend reflog when you rebased (on) the wrong commit and you want to undo a successful rebase.

Re: How to Squash and Rebase in Git

#56

For ardour, we almost never squash commits because we prefer our (always linear) git history to show the actually "story" of a branch's development. There are two exceptions. 1. branch developer suffered from several "thinkos" along the way, the branch doesn't contain that many changes, and there's simply no benefit to seeing the contrast between the initial (mistaken) changes and the final result. 2. the branch comm…

You have no way of knowing if a developer squashed locally...

Correct. Rules for this stuff are pointless, but guidelines to generally follow are not.

Re: How to Squash and Rebase in Git

#57
post #11

Semi-related: my favorite dev tool is diff2html I aliased `diff` to open up my browser showing me the full diff of what I'm working on - super useful! https://diff2html.xyz/

How does this differ from “git difftool” with something like Meld installed?

Re: How to Squash and Rebase in Git

#58
post #5

I recently started using `git commit --fixup` which I really like. It lets you take the current changes and apply them to a commit which is not the most recent (in a fairly roundabout way). It's good for when I have a stack of diffs and want to make changes to multiple commits at once. (Note this is a pretty advanced technique, if you're not super comfortable with `git rebase -i` I wouldn't bother even trying to unde…

if you do this often and want some automation, `git absorb` [1] may be worth a look. it will try to find lines that can be unambiguously attributed to a diff based on when the line and its surrounding lines are last modified, and then generate fix-up commits or amend existing ones.

[1]: https://github.com/tummychow/git-absorb

Re: How to Squash and Rebase in Git

#59
post #21

10+ years and I still don’t understand why developers and orgs think it’s necessary to squash and rebase.

I've seen two main arguments to that workflow. One argument, and which I hear often, is that they want to keep the git history clean. The other argument is that keeping things rebased & squashed allows you to do reverts easily. I personally don't mind the merge commits cluttering the history, and especially when working on a longer lived branch I will always prefer merging-in changes rather than constantly rebasing a…

You can do reverts just as easy with merge commits.

git revert -m 1 $commit

You can also visualize a clean history with merge commits.

git log —-first-parent

The only argument I’ve heard that holds weight is that GitHub’s UI squashes the merge commit history into a linear view.

Post reply on HN