CircleCI short object hash does not match git's

The short form of the git object SHA1 hash (e.g. 80cf7b3) that CircleCI displays throughout the web UI does not always match git’s own short hash computation. This is quite annoying, since it means you cannot for example copy the value from CircleCI to use as an input somewhere else (script parameter, artifact filenames that contain the hash, etc.) and expect them to match. In a sufficiently large repo, CircleCI’s short hashes may also collide.

How they differ:

  • CircleCI appears to use a fixed 7 character prefix of the object’s SHA1.
  • Git on the other hand uses a variable number of characters for the short hash based on the size of the repository (examples include: ‘git log --pretty=format:"%h"’ or ‘git rev-parse --short HEAD’). The short hash length is defined in the man page as: “an appropriate value is computed based on the approximate number of packed objects in your repository”.

We’ve got a pretty large repository where the hash length has increased to 8 characters, and it’s annoying to always have to remember that the CircleCI hash no longer matches our repository’s. It would be nice if CircleCI just used the output of “git rev-parse --short” for the short hash.