【问题标题】:MD5 hash of file changes after comitting, deleting and fetching from git从 git 提交、删除和获取后文件更改的 MD5 哈希
【发布时间】:2022-04-12 01:40:43
【问题描述】:

如果要执行以下操作:

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

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

【问题讨论】:

  • 你看过行尾吗?他们一致吗?一些管道将CR LF 自动格式化为LF
  • 就像一个注释,MD5 现在对于几乎所有用途都完全没用。请改用 SHA-256 或 BLAKE2b。

标签: python git hash md5


【解决方案1】:

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

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

“错误”以外的任何内容都可能导致您观察到的行为。

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2014-10-29
    • 2012-12-31
    相关资源
    最近更新 更多