Referencing Gitlab issues in commit messages

Since recently I’m working on an open source project hosted on a Gitlab instance. We also manage project issues in Gitlab and in my commit messages I reference those issues, where appropriate. I do this by prefixing the commit message with a hashmark and the issue number. A commit message can look like that:

#123: Demo commit message

In Gitlab, this will result in a clickable reference to the corresponding project issue – very handy. Unfortunatly, the syntax chosen by Gitlab (it’s the same for Github and other platforms as well, btw.) interferes with standard Git behaviour: a leading hashmark is used as a comment designator. You can use a hashmark when you define a commit message on the command line using the git commit -m parameter. But you are in trouble if you want to write a commit message in an editor or if you do a rebase where you have to edit commit messages. I expected that I can simply escape the hashmark, but it seems there’s no way to do this. You can fix this by adjusting your git configuration, though.

One option is to change the comment character. This way, the hashmark won’t interfere anymore with the comment sign:

git config --global core.commentChar ";"

You can also adjust the cleanup mode used by git when processing commit messages:

git config --global commit.cleanup scissors

This will configure git to add a scissors line and cleanup everything below that line. The scissors line looks like that:

# ------------------------ >8 ------------------------

You can use either of those options or even combine them. As a result you can now use the hashmark in commit messages.

References