Adding the PR number to commit messages

I’ve seen a lot of repositories where every single commit is suffixed with the respective PR number in parentheses. I’ve decided that I’d like to do this in my own repositories.

I’d assumed that the merge commit message was just being changed manually by whoever is responsible for merging, but on inspecting things more closely, that doesn’t appear to be the case. Merge commit messages aren’t visible in Github’s code browser, but every file has the PR number attached. Here’s github/linguist as an example:

My next thought was that the each commit simply has the PR number in the commit message. But that’s stupid and an unreasonable demand for contributors. Looking at the commits in each PR, they don’t feature the PR number at all - not even the merge commit. Here’s an example from github/linguist: https://github.com/github/linguist/pull/5081/commits

I can see that the merge was made on github.com, so there’s not any fancy command-line tools at play here. This should be achievable via the web interface - right? And it’s not a Github Action, either, given that the only workflow in github/linguist is CI.

How do I automatically and reliably add PR numbers to commits?

I believe this happens when you use the “Squash and merge” option in the web UI.

1 Like