Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MD5 hash of file changes after comitting, deleting and fetching from git

Tags:

git

python

hash

md5

If one were to do the following:

def hashmdfive(filename):
    """Generate the md5 checksum."""
    hasher = hashlib.md5()
    with open(filename, "rb") as afile:
        buf = afile.read()
        hasher.update(buf)
    return hasher.hexdigest()
  1. make a file (e.g. test.txt) with some content.
  2. create hash of file by running hashmdfive above.
  3. committing and pushing to a remote git repo
  4. delete local file.
  5. fetching test.txt from remote
  6. create new hash of file by running hashmdfive above.

THE HASHES ARE DIFFERENT. Does anyone know why that is the case?

like image 460
TangoAlee Avatar asked Sep 01 '25 20:09

TangoAlee


1 Answers

If you are running on Windows, git's autocrlf feature can be the cause of a digest changing:

This will show you the current value: git config --global core.autocrlf

Anything other than "False" can result in the behavior you are observing.

like image 113
Erik Aronesty Avatar answered Sep 03 '25 10:09

Erik Aronesty