In git, what is the difference between long and short hashes?

Here is the long git hash:

commit c26cf8af130955c5c67cfea96f9532680b963628

  • I copy a git repo into another git repo, how to restore?
  • How do I set the git username and password when using gitpython?
  • Cannot build with TeamCity and one git submodule
  • Can deleted .git be restored?
  • dvcs partial merge (git, hg merge tracking)
  • .bash_history does not update in Git for Windows (git bash)
  • Merge: 8654907 37c2a4f

    Author: nicolas

    Date: Wed Apr 26 13:28:22 2017 -0400

    Here is the short one

    enter image description here

  • Organizing a git repo that belongs inside another repo
  • GIT: Get Bash Here on network location
  • Running git daemon with read only user gives “fatal: cannot drop privileges”
  • Changing branches in git mistakenly results in modified files
  • Resharper cannot rename files when Git version control is applied
  • Merge 2 Different git Repos
  • 4 Solutions collect form web for “In git, what is the difference between long and short hashes?”

    A short hash is just the first 7 characters of your full hash.

    Right below the circled commit in your screenshot, you can see a commit labeled c26cf8a. This should be the commit c26cf8af130955c5c67cfea96f9532680b963628 you were looking for.

    To elaborate a bit more about why the short hash is useful, and why you often don’t need the long hash, it has to do with how Git stores things.

    c26cf8af130955c5c67cfea96f9532680b963628 will be stored in one of two places. It could be in the file .git/objects/c2/6cf8af130955c5c67cfea96f9532680b963628. Note that the first two characters, c2, make up a directory and the rest is the filename. Since many filesystems don’t perform well when there’s too many files in one directory, this prevents any one directory from having too many files in it and keeps this little directory database efficient.

    With just the short hash, c26cf8a, git can do the equivalent of .git/objects/c2/6cf8a* and that’s likely to be a single file. Since the objects are subdivided into subdirectories, there’s not too many filenames to look through to check if there’s more than one match.

    c26cf8a alone contains enough possibilities, 16^7 or 2^28 or 268,435,456 that it’s very unlikely another commit will share that prefix.

    Basically, Git uses the filesystem itself as a simple key/value store, and it can look up partial keys without having to scan the whole list of keys.


    That’s one way to store objects. More and more, Git stores its objects in packfiles. It’s a very efficient way to store just the changes between files. From time to time, your Git repository will examine what’s in .git/objects and store just the differences in .git/objects/pack/pack-<checksum>.

    That’s a binary format, I’m not going to get into it here, and I don’t understand it myself anyway. 🙂

    Short hash is just shorter version of original(long) hash. original git hash is 40 bytes long while short is only 8 bytes long. However it becomes difficult to manage it (in terms of using typing or displaying) that’s why the short version is used.

    This approach is used in almost all the projects where hash is either for integrity(package distribution), versioning(git/svn) or layered architecture(docker).

    Decided to turn my initial comment into an answer.

    Short hash shows the first 7 characters of hash. Short hash of c26cf8af130955c5c67cfea96f9532680b963628 is c26cf8a in second row. See docu:

    Git is smart enough to figure out what commit you meant to type if you provide the first few characters, as long as your partial SHA-1 is at least four characters long and unambiguous

    Git Baby is a git and github fan, let's start git clone.