TIL: Gitlab's default squash behaviour deletes commit messages
Something that's in the docs, but still painful when unexpectedly encountered in the wild.
Gitlab 14.6 introduced squash commit templates. If someone ticks the "Squash commits" checkbox in a merge request, the repo's squash template is used when merging. Unfortunately, the default template is
%{title}
That's the title of the merge request and nothing else. All commit messages are dropped.
In git itself, that isn't squash behaviour. The git docs on Rewriting History describe squash as "use commit, but meld into previous commit" and fixup as "like 'squash', but discard this commit's log message".
Gitlab's default "squash" template effectively fixups the entire MR.
This seems to have been the case from the introduction of squash templates in Gitlab 14.6 and is still the case in Gitlab 16.3. Luckily, commit templates support plenty of variables and more conventional squash behaviour can be achieved by changing the default squash template to
%{title}
%{all_commits}
Useful things
- Gitlab's docs explain how to configure a repository's commit templates