64

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.

daniel.heydebreck
  • 768
  • 14
  • 22
Juraj Martinka
  • 3,991
  • 2
  • 23
  • 25
  • why do you want to know the size? any specific background or reason? – fajran Mar 16 '12 at 08:06
  • 1
    If there's no limit, you can use Github's API as an append-only persistent log, with operations saved in commit messages as immutable log entries. Then you code the rest of the app as a set of data transformations: blog.confluent.io/2015/03/04/turning-the-database-inside-out-with-apache-samza/ – agentofuser Mar 05 '15 at 22:11
  • If you're here looking for *best practices* around git commit message max length -- rather than the max length possible -- then this is relevant: https://stackoverflow.com/q/2290016/12484 – Jon Schneider Aug 02 '22 at 14:53

3 Answers3

64

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
Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
huon
  • 94,605
  • 21
  • 231
  • 225
40

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.

Amber
  • 507,862
  • 82
  • 626
  • 550
7

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.

Doug Robinson
  • 71
  • 1
  • 3