Live data from Hacker News

Idiot Proof Git

softwaredoug.com

51–60 of 435 posts

Re: Idiot Proof Git

#51
post #48

What's the deal with squashing commits anyways? I'm genuinely asking, because I've only worked with "squash everything before you put it up for review" but have never really figured out why past "it's what we've always done".

fix typo

yet another typo

test fix

aaah, why is this test failing?

merge foobar/narf

revert foo

foo

Is just not a good history to preserve

Re: Idiot Proof Git

#52
post #10

Earlier quoted context omitted.

Obviously what works for you works for you, but I respectfully disagree with everything you said. The "history should be exactly what you did" argument - which many people make - is really funny to me because a pull/merge-only strategy only preserves the _wrong_ history. As a tech lead, for example, I absolutely do not care one bit about the date of a commit, or when the developer started working on it, or what was t…

The log should track the product's evolution, not the developers' activities. Git is a development tool, not a product release tool. If you want to see the product evolution you could filter to just merge commits, or just merge commits in a specific format. If you want to keep track of releases specifically, then use tags, that's what they're for. I suppose you could make a separate branch/repo where every commit = a…

At the end of the day everything depends on the organization. In a hectic startup where requirements change on an hourly basis and releases are made several times a day, I would absolutely insist on keeping the log linear and as clear as possible. Tags are important, of course, but they're not that useful for analyzing a repository.

When I say "the evolution of the product" I really mean "the "evolution of the code". When a small feature branch with 5 commits - four of which say "wip" and the last one says "added color support" - gets merged as is, and all relevant information is held hostage by whatever Git platform the company is using this week and not inside the repository itself, the log is not useful to me regardless of any strategy.

But in a different setting I would not necessarily insist in the same way.

Re: Idiot Proof Git

#53
post #48

What's the deal with squashing commits anyways? I'm genuinely asking, because I've only worked with "squash everything before you put it up for review" but have never really figured out why past "it's what we've always done".

So that atomic changes are consolidated in a single commit/PR.

Sometimes, the flow for a single feature A: - commit change AA - commit change AB - fix change in AA - extend AB

In this case, until merged into main/master and to reduce noise for the reviewer (especially if using a code review each commit type process), its best to squash all commits into a single "feature A".

Re: Idiot Proof Git

#54
The problem with git is hardly anyone reads the fucking manual. Git is not hard. The UI is inconsistent, but documented. When you just foist commands onto people, you can't be surprised when they fall off the happy path and don't have the mental model to understand how to fix it. There's no such thing as "idiot-proofing" for people who don't RTFM.

--force-with-lease as a default is a really bad idea. Copying random aliases is a bad idea.

Re: Idiot Proof Git

#55
post #50
post #18

--force-with-lease can be a footgun. It will overwrite the tree on remote as long as remote hasn't changed since you last fetched it. It doesn't always work, particularly if you have a tool which continuously fetches remote, like an IDE configured to do so such as VSCode. In that case, you will have fetched the other person's changes, and --force-with-lease will happily blow-away anything on remote that might not be…

Yes, but it's still better than --force under most circumstances.

Why use force at all, on a default command?

Re: Idiot Proof Git

#56
post #48

What's the deal with squashing commits anyways? I'm genuinely asking, because I've only worked with "squash everything before you put it up for review" but have never really figured out why past "it's what we've always done".

So you can get a semantic and useful history before submitting a patch/PR for review (or before merge).

Doing hacky and messy WIP commits is totally fine. Just clean them up before having others read them.

In case you're not aware:

  git rebase --interactive [remote/]ref

Re: Idiot Proof Git

#57

Rebase should never be used. Or, if it is used, it should be treated as a dangerous thing to do that’s well outside the norm. Most of the arguments in favor of rebase are by people fanatical about having a git history organized just so. It’s not worth the headache and effort. PRs are a better unit of work than commits in practice. Configure GitHub or whatever you use to squash merge only and you’ll be good. Since mov…

Quoted post unavailable.

I use rebase, for two reasons:

1. (major): it lets me commit at my pace, and then publish my work at the pace the team prefers (which is a combination of what the team wants and what won't choke the CI, but that's a story for another time). The ratio of my local commits to commits sent to code review is often 5-10:1.

2. (minor): because I hate to see a Git history that's over 50% made of "Merged X, Y into develop". It's pure noise. I guess there's probably a command line flag to filter them out, though.

Re: Idiot Proof Git

#58
I like those aliases if you are doing for yourself, but I dislike for beginner (to git) using them to make git "easier". Git UX is confusing and has growing pains I won't deny it, but git is widely used and imho one should take some time to at least understand the basics.

I dislike even more the default of many IDE and some git server, they seem to push for the worse git habits.

Re: Idiot Proof Git

#59
post #48

What's the deal with squashing commits anyways? I'm genuinely asking, because I've only worked with "squash everything before you put it up for review" but have never really figured out why past "it's what we've always done".

So there's (at least) two uses for commits.

The first is to keep a log of what you are working on. For me, that's lots of small and dumb commits.

The second is to provide a story for review.

Most of the time, when the change you are putting out for review is small and simple, you can just put it all into a single commit.

Sometimes, your change is more complicated and it makes sense to break it into a series of related commits. Along the line of 'first do the refactor that makes the complicated change simple, then make the simple change'.

Your job as an author is to hide the ugly reality of how you actually came up with the change, and present the reviewer a sanitised view of reality. Reviewing code is hard, so it's best to make it as easy as possible.

Re: Idiot Proof Git

#60

Rebase (non-local rebase) based workflows are just awful. The best git methodology I've seen is (surprise, surprise) in the Linux kernel. I can keep everyones tree as a separate tracking branch and use git work trees to develop against multiple branches on the same system. I also really enjoy using git request-pull, send-email, etc. and I think Github has been actively harmful in teaching people bad git habits.

Rebasing remote feature branches after feedback in the github-pull-request workflow is analogous to re-sending and updated patch series in the email workflow.

The distinction shouldn't be if its remote or not but if its something "published" that others might build their work upon.

Post reply on HN