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

  • Home
  • SEARCH
  • 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
  • 0 Views
  • 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

Ask A Question

Stats

  • Questions 127k
  • Answers 127k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This declares iterator to be a variable (not a type):… May 12, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer You can't have custom attributes on a generic type argument… May 12, 2026 at 5:35 am
  • Editorial Team
    Editorial Team added an answer i wrote a hack for a phpbb once, but right… May 12, 2026 at 5:35 am

Related Questions

My understanding of the Git pack file format is something like: Where the table
I'm having a hard time understanding some git/DCVS concepts. Here's what happened: I created
I often need to develop stuff on the road, with no internet/network connection. I
How do I set up a Git project to contains other projects? eg. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.