从 git 提交、删除和获取后文件更改的 MD5 哈希值

Tan*_*lee 4 python git hash md5

如果要执行以下操作:

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()
Run Code Online (Sandbox Code Playgroud)
  1. 创建一个包含某些内容的文件(例如test.txt)。
  2. 通过运行上面的 hashmd Five 创建文件的哈希值。
  3. 提交并推送到远程 git 存储库
  4. 删除本地文件。
  5. test.txt从远程获取
  6. 通过运行上面的 hashmd Five 创建新的文件哈希。

哈希值不同。有谁知道为什么会这样?

Eri*_*sty 6

如果您在 Windows 上运行,git 的 autocrlf 功能可能是摘要更改的原因:

这将显示当前值: git config --global core.autocrlf

除“False”之外的任何内容都可能导致您所观察到的行为。