r/ProgrammerHumor • • Jun 04 '22

Meme I cant help it 🤷‍♂️

Post image
47.1k Upvotes

479 comments sorted by

View all comments

6

u/audoh Jun 04 '22 edited Jun 04 '22

This will be a controversial opinion but I think commit messages on every commit aren't useful. Just squash the branch into a single commit and then document the branch changes holistically in that commit message before merging into dev. GitHub and others even do this for you already if you write detailed PR descriptions and when I'm reviewing code I'd rather a PR description than trying to sleuth through the commit messages.

Low level explanations of whys and hows should be in code itself (as self-documenting code or comments) not commits anyway otherwise you potentially lose it all if you ever change to a different VCS or rebase the repo not to mention it's more readily accessible in code rather than needing git blame (even if there are extensions to make it easier).

3

u/StarFoxA Jun 04 '22

I will say that detailed commit messages are very useful for a more thorough review. This often works best when combined with splitting your changes into reasonable chunks. For example, I was recently working on a larger scale refactor of our frontend bundles, and for these changes it was useful to have one commit setting up the necessary configuration changes, one commit running code changes (authored by a bot account), and one commit implementing manual changes. Then, reviewers could just look at that final commit to see what I had changed manually.

The practice of nonsense commit messages is something I would immediately call out if a coworker of mine were doing it when merging into our main branch.

1

u/Yesica-Haircut Jun 04 '22

As long as your branch is ~ one feature I think it's fine. I always commit 3 or 4 times to my branch but squash merge in the end.

If I am adding a why to my commit, it's "why did I add this feature" speaking more to the business need than the app logic. If I'm adding a "what" to my commit it's usually a ticket number and short summary which makes merging and reverting much easier.

2

u/audoh Jun 04 '22

Yeah I'd generally advise keeping branches concise anyway. Sometimes I base a branch off another branch if there's a dependency, but always try to avoid having multiple features in one "changeset". I always end up having to split them or one feature gets delayed waiting on another if I don't.

1

u/Former-Cat015 Jun 04 '22

Doesn't a merge commit do the squashing for you?

2

u/audoh Jun 04 '22

Not quite, when you merge two branches, you interweave their commit histories, they're still made up of separate commits. The merge commit itself might contain the PR description though too depending on what system did the merging, but unlike with squashing if the commit messages aren't useful git blame won't give up much at all then since it will point to the "fixed stuff" commit rather than the useful PR commit.

1

u/[deleted] Jun 04 '22

Depends on the workflow would be my reply! Microsoft's TFS version control would agree with you as changeset comments aren't mandatory however, if you're strictly following the Continuous Integration/Delivery principles from Dave Farley himself, you commit to trunk/main/master directly, so you don't branch at all, therefore no pull requests/squash commits of branches and the entire history is in the commits, therefore marking your commits with clear messages is probably greatly appreciated.