After working on a project that had code commit linters like this, that block you from committing if there's a violation, it's absolutely awful. You cannot work incrementally at all since "inject logger" is not a feature. Since most people aren't comfortable with rebasing (i don't know why), you end up with a ton of nonsense like a whole chain of refactors or feats that aren't actual refactors or features, they're just there to appease the tool since you can't commit (even locally!) without them.
Just stick to squash-before-merge-to-master, thanks.
Squash merge and commit linter only on master seems like the way to go here.
Then you can do whatever you want in your feature branch, and then when the feature is ready, create the squashed commit with the proper commit formatting.
squash merges to master are terrible for those that want to go looking why a certain change was introduced.
Now a larger change set is hidden behind a squash merge, and why was line 50 in foobar.py updated? Who knows, it was part of this giant merge request which no longer provides context why the developer changed line 50 in foobar.py.
Commit messages should explain why the change was made to the code. The amount of times that I go diving into a codebase only to find that the change was introduced in a larger commit that just says "fix bug" with no further information is maddening.
You're describing the wrong use of squash merges, and I agree they suck.
The right use is to allow me to make crappy, random commits on my own feature branch, clean them up those commits when I'm ready to release the change.
And the commit description will describe what's going on.
The key is that my feature branch is not long-lived - only a day or two, long enough for me to make a step forward before merging it back into mainline and then starting on the next step.
If you do this for short-lived feature branches only, why do you even need to squash merge for this? What I typically do for such things is to have a WIP commit that I amend and force push while working on the feature, then when everything is ready to merge I reset —-soft and make separate commits for each part of the work that can be compiled and tested indivually, rebase onto master and then fast-forward merge.
Even for a short lived feature branch that lasts maybe a day or so there may be a bug you find during testing that you quickly fix, or a change you make in existing code to help support the new feature or something you know is coming down the pipeline, and that information is now lost.
Or you could make consideration for tracking that change in source code a priority when making those changes and code appropriately.
The problem you describe is a problem because people are not prioritizing or valuing the commit history as a resource. If you fix that, then people will think about these things differently.
Squash and merge is not the only way to get things into master. You can rebase and squash commits as needed on your branch and then bring multiple commits from your branch onto master. That takes more advanced usage of git, but learning that makes sense once you start really valuing the history.
This was so bad at one point that I changed my git aliases to include '--no-verify'.
I like to push all my commits up so I can pull them back on a different machine or get early feedback. I'll typically rebase at the end with a proper commit message and explanation for each logical change.
I've been working on a project for months that uses this exact setup (commits are rejected if they are not formatted correctly) and the problem you describe just isn't that big of a deal. The benefits to the projects far outweigh the mild inconvenience.
I totally agree. I think the complaints are valid, but to be honest it seems petty. There are ways around it like you suggested. Having stuff like this really helps to solve process problems like not keeping a changelog up to date or incorrect version bumps, that can be a pain to manage across engineers. I think it’s important to consider that it helps the team as a whole.
I'm the original co-author of the "Conventional Commits" spec. Although, I should give credit where credit is due, and say that it evolves directly from Angular commit conventions.
I started adopting these conventions with the goal of automating releases, both on my open-source and on the services I was working on at npm (I've since brought the practice to my team at Google).
I very much did not want to introduce road blocks to folks committing to their own branches -- which is what the "rewrite the message when you squash" advice grows from.
Here's a post I wrote on how my team uses Conventional Commits in our release process:
> Example: Commit message with both ! and BREAKING CHANGE footer:
> refactor!: drop support for Node 6
From Wikipedia's Code Refactoring:
> In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior.
So if a code change is just a refactor, then its external behavior is unchanged, therefore it is not a breaking change. These two commit labels are incompatible.
Once the decision has been made that Node 6 is no longer supported, it is then possible to refactor the code so that it uses appropriate modern idioms, such that the external behaviour is unchanged for Node 6+ but will no longer be parsable by Node 5.
In this specific case, it is both a refactor and a breaking change.
The most interesting things about Conventional Commits are that they can be deterministically digested by a process to decide how to bump a SemVer and similarly to create a formatted CHANGELOG file.
I really wished we had type systems good enough, and tools smart enough to figure the semver bump by it self. Ideally humans should not come near semver bumping, not even through the commit messages.
My take on this is that, all else being equal, it seems the major selling point of Conventional Commits is that their commit summaries can be used to calculate the next version bump. But IMHO, instead of asking everyone to annotate every single commit message with a marker just so a separate tool can process it (possibly to get it wrong), it's better to just update the version directly when making changes. This way the version bump is deliberately and carefully thought out, and doesn't need to pollute all commit messages in the process.
After working on a project that had code commit linters like this, that block you from committing if there's a violation, it's absolutely awful. You cannot work incrementally at all since "inject logger" is not a feature. Since most people aren't comfortable with rebasing (i don't know why), you end up with a ton of nonsense like a whole chain of refactors or feats that aren't actual refactors or features, they're just there to appease the tool since you can't commit (even locally!) without them.
Just stick to squash-before-merge-to-master, thanks.
Squash merge and commit linter only on master seems like the way to go here.
Then you can do whatever you want in your feature branch, and then when the feature is ready, create the squashed commit with the proper commit formatting.
squash merges to master are terrible for those that want to go looking why a certain change was introduced.
Now a larger change set is hidden behind a squash merge, and why was line 50 in foobar.py updated? Who knows, it was part of this giant merge request which no longer provides context why the developer changed line 50 in foobar.py.
Commit messages should explain why the change was made to the code. The amount of times that I go diving into a codebase only to find that the change was introduced in a larger commit that just says "fix bug" with no further information is maddening.
You're describing the wrong use of squash merges, and I agree they suck.
The right use is to allow me to make crappy, random commits on my own feature branch, clean them up those commits when I'm ready to release the change.
And the commit description will describe what's going on.
The key is that my feature branch is not long-lived - only a day or two, long enough for me to make a step forward before merging it back into mainline and then starting on the next step.
If you do this for short-lived feature branches only, why do you even need to squash merge for this? What I typically do for such things is to have a WIP commit that I amend and force push while working on the feature, then when everything is ready to merge I reset —-soft and make separate commits for each part of the work that can be compiled and tested indivually, rebase onto master and then fast-forward merge.
I think you just answered your own question. Compared to your workflow, the squash-merge workflow allows:
- Commit and push naturally as you work
- Reviewers to look at individual commits separately after having already reviewed previous commits
- Squash-and-merge with one click (usually, e.g. GitHub) instead of messing around with git resets and branch history.
Even for a short lived feature branch that lasts maybe a day or so there may be a bug you find during testing that you quickly fix, or a change you make in existing code to help support the new feature or something you know is coming down the pipeline, and that information is now lost.
You can say that about any commit in the repo, no matter how granular the commits are.
Or you could make consideration for tracking that change in source code a priority when making those changes and code appropriately.
The problem you describe is a problem because people are not prioritizing or valuing the commit history as a resource. If you fix that, then people will think about these things differently.
Squash and merge is not the only way to get things into master. You can rebase and squash commits as needed on your branch and then bring multiple commits from your branch onto master. That takes more advanced usage of git, but learning that makes sense once you start really valuing the history.
The linters can probably be configured to look for the squash!/fixup! indicators in commit messages and throw a warning or something instead.
This was so bad at one point that I changed my git aliases to include '--no-verify'.
I like to push all my commits up so I can pull them back on a different machine or get early feedback. I'll typically rebase at the end with a proper commit message and explanation for each logical change.
There's an easy workaround: use the "chore" tag.
I've been working on a project for months that uses this exact setup (commits are rejected if they are not formatted correctly) and the problem you describe just isn't that big of a deal. The benefits to the projects far outweigh the mild inconvenience.
I totally agree. I think the complaints are valid, but to be honest it seems petty. There are ways around it like you suggested. Having stuff like this really helps to solve process problems like not keeping a changelog up to date or incorrect version bumps, that can be a pain to manage across engineers. I think it’s important to consider that it helps the team as a whole.
Hey,
I'm the original co-author of the "Conventional Commits" spec. Although, I should give credit where credit is due, and say that it evolves directly from Angular commit conventions.
I started adopting these conventions with the goal of automating releases, both on my open-source and on the services I was working on at npm (I've since brought the practice to my team at Google).
I very much did not want to introduce road blocks to folks committing to their own branches -- which is what the "rewrite the message when you squash" advice grows from.
Here's a post I wrote on how my team uses Conventional Commits in our release process:
https://dev.to/bcoe/how-my-team-releases-libraries-23el
> Example: Commit message with both ! and BREAKING CHANGE footer:
> refactor!: drop support for Node 6
From Wikipedia's Code Refactoring:
> In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior.
So if a code change is just a refactor, then its external behavior is unchanged, therefore it is not a breaking change. These two commit labels are incompatible.
Once the decision has been made that Node 6 is no longer supported, it is then possible to refactor the code so that it uses appropriate modern idioms, such that the external behaviour is unchanged for Node 6+ but will no longer be parsable by Node 5.
In this specific case, it is both a refactor and a breaking change.
I think they use the angular definition which doesn't explicit forbid this
> refactor: A code change that neither fixes a bug nor adds a feature
But yeah I'm with you in saying that this particular example is not well choosen
The most interesting things about Conventional Commits are that they can be deterministically digested by a process to decide how to bump a SemVer and similarly to create a formatted CHANGELOG file.
^ https://github.com/semantic-release/semantic-release
Yeah, https://github.com/conventional-changelog/standard-version is a really great tool for this, we use it and the versioning is relatively seamless for releases.
I really wished we had type systems good enough, and tools smart enough to figure the semver bump by it self. Ideally humans should not come near semver bumping, not even through the commit messages.
Elm does have a type-directed version bump tool. Is that what you were thinking of?
My take on this is that, all else being equal, it seems the major selling point of Conventional Commits is that their commit summaries can be used to calculate the next version bump. But IMHO, instead of asking everyone to annotate every single commit message with a marker just so a separate tool can process it (possibly to get it wrong), it's better to just update the version directly when making changes. This way the version bump is deliberately and carefully thought out, and doesn't need to pollute all commit messages in the process.