Maximum commit message size

Git

Git Problem Overview


Is there any size limit to the Git commit message? I searched trough the web but cannot find any relevant mention about this except this one.

However, that one does not answer my question.

Git Solutions


Solution 1 - Git

Empirically, I think the answer is no. This worked (that's a ~100MB commit message):

yes | head -c 100000000 | git commit -F - > /dev/null

Command parts explanation:

  • yes repeats "y\n" forever
  • head -c 100000000 takes only the first 100,000,000 bytes (~100MB)
  • git commit -F - commits with the passed-in commit message (this won’t work if you haven’t staged any changes to commit)
  • > /dev/null hides the output from the command, which includes Git repeating back the very long commit message

Solution 2 - Git

https://github.com/git/git/blob/master/strbuf.h defines the len field to be a size_t. So at the very least, the maximum length has an upper bound at the maximum value of size_t on your platform of choice.

Solution 3 - Git

Well, actually, there is a limit of ~5MB for JGit.

Of course, I've got to ask why anyone would do that?! Especially since every subsequent clone would need to include that data. I'd say that if you're going beyond a few KB then you really should be questioning your motives.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuraj MartinkaView Question on Stackoverflow
Solution 1 - GithuonView Answer on Stackoverflow
Solution 2 - GitAmberView Answer on Stackoverflow
Solution 3 - GitDoug RobinsonView Answer on Stackoverflow