Search code examples
git

Should ticket/PR number be in commit header


I see many people put the ticket/PR number in the git commit header. I think it only adds clutter when you read git log because as human those numbers do not tell you anything.

Putting the numbers in the commit message (anything after the blank line) will make much more sense as it will keep the record that this commit fixes/related to that issue and will allow for easy search but will leave the log clean and readable.

I'm trying to find the answer to why people do that?


Solution

  • I agree with you in principle, the less clutter in the commit Subject line the better. I wouldn't say though that these references are useless for humans though, because many tools can automatically link ticket ids to the corresponding ticket in a log overview (where oftentimes only the subject line is shown by default). Still, the subject line should provide enough context to reveal what the commit is about, without requiring the reader to follow links.

    For GitHub ticket ids one has to be careful though, to not put them at the start of the line, because they start with a # which is interpreted as a comment line by git so it will not be included in the message.

    I think technically the best solution would be to put related ticket numbers as "metadata" into commit message trailers. If the industry could agree on common conventions there, tools could support that as well, but until that happens I suppose people will continue to use the subject line for ticket ids.