Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:22:47+00:00 2026-05-11T05:22:47+00:00

As I understand it when Git assigns a SHA1 hash to a file this

  • 0

As I understand it when Git assigns a SHA1 hash to a file this SHA1 is unique to the file based on its contents.

As a result if a file moves from one repository to another the SHA1 for the file remains the same as its contents have not changed.

How does Git calculate the SHA1 digest? Does it do it on the full uncompressed file contents?

I would like to emulate assigning SHA1’s outside of Git.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:22:48+00:00Added an answer on May 11, 2026 at 5:22 am

    This is how Git calculates the SHA1 for a file (or, in Git terms, a ‘blob’):

    sha1('blob ' + filesize + '\0' + data) 

    So you can easily compute it yourself without having Git installed. Note that ‘\0’ is the NULL-byte, not a two-character string.

    For example, the hash of an empty file:

    sha1('blob 0\0') = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'  $ touch empty $ git hash-object empty e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 

    Another example:

    sha1('blob 7\0foobar\n') = '323fae03f4606ea9991df8befbb2fca795e648fa'  $ echo 'foobar' > foo.txt $ git hash-object foo.txt  323fae03f4606ea9991df8befbb2fca795e648fa 

    Here is a Python implementation:

    from hashlib import sha1 def githash(data):     s = sha1()     s.update('blob %u\0' % len(data))     s.update(data)     return s.hexdigest() 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that a .gitignore file cloaks specified files from Git's version control. How
I'm struggling to understand how to be able to clone a git repository from
Which is efficient? SSH:// or Git:// (File compression) I understand in Git, git protocol
Coming from an svn background, I had this question: git equivalent of svn status
If there is anyone that can help me understand why this git repo isn't
I understand that git diff compares a staged file and modified but not staged
If I understand correctly one of the advantages of Git is that everybody has
I am trying to understand the code in this page: https://github.com/corroded/git-achievements/blob/gh-pages/git-achievements and I'm kinda
Is there a way to programmatically download a single file from a remote git
I'm starting to understand git but I'm still having some trouble with the abstraction.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.