My code is the following
system('git log --pretty=format:[%h]: %an')
7 digits is the default and is the generally accepted minimum to ensure uniqueness on moderate sized projects. Anything less runs the risk of collisions. If you want to trim it you can ask:
This may be overruled by the
git command if the 5 digit values are not unique. Consider this value a minimum and not a maximum.
You can read more with
git log --help.
As a note, you generally want to break out arguments to
system to avoid confusion between them:
system("git", "--log", "--pretty-format=...")
That's especially necessary when passing in arbitrary filenames as those can be interpreted by the shell in ways that are hazardous.