Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is a commit hash, and why is it such a long string?

SHORT ANSWER

A commit hash is a SHA-1 fingerprint of the commit's contents, author, message and parent. It uniquely identifies the commit and changes if anything inside it changes. You can usually use just the first 7 characters.

Explain it simply

A hash is like an Aadhaar number for a commit, except it is calculated from the commit itself rather than handed out. Git feeds the snapshot, the author, the date, the message and the parent's hash into SHA-1 and gets 40 hexadecimal characters.

That has two consequences. First, two different commits practically never share a hash. Second, because the parent's hash is part of the input, changing an old commit changes every hash after it. That is why rebasing rewrites history and why Git can detect corruption.

Typing 40 characters is painful, so Git accepts any unique prefix, commonly 7 characters. Newer Git can use SHA-256, but SHA-1 is still the default.

Example

bash
git log --oneline
# 3f9c2ab Add payment page
# 81d04e7 Fix cart total
git show 3f9c2ab           # short prefix is enough
git rev-parse HEAD         # full 40-character hash

What to say in the interview

"A commit hash is a SHA-1 checksum computed from the commit's content, metadata and parent hash. It identifies the commit uniquely, and since it includes the parent, changing any old commit changes all later hashes. In daily use I type only the first seven or so characters."

#git#commit#hash

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.