使用 core.autocrlf=true 时文件的 'git hash-object' 结果不同?
Result of 'git hash-object' for a file different when using core.autocrlf=true?
我通过提供 git 文件 blob(文件内容哈希)使用 git log --find-object
到 identify commits。
这很好用,我之前使用 git hash-object
获取文件的 blob
但是,当我为同一个文件发出 git hash-object
时, 并且我设置了 core.autocrlf=true
,我得到了一个不同的 blob(散列值) .
因此 git log --find-object
没有识别对应于那个 'new' blob 的提交。
这里发生了什么?这是否意味着 git hash-object
在 core.autocrlf=true
时不 'work'?
将文件写入数据库时,core.autocrlf
告诉 git
对所有输入文件进行 运行 过滤器,将 CRLF 行结尾转换为 LF。它必须在计算 blob 的哈希之前执行此操作,因为根据定义,您更改的每个字节都会影响哈希。
由于 git hash-object
是用于执行此操作的管道命令,因此它也必须执行这些过滤器。如果你想抑制它,并在没有过滤器 运行 的情况下找到文件的哈希值,你可以使用 --no-filters
选项。 Manual summary:
--no-filters
Hash the contents as is, ignoring any input filter that would have been chosen by the attributes mechanism, including the end-of-line conversion. If the file is read from standard input then this is always implied, unless the --path option is given.
我通过提供 git 文件 blob(文件内容哈希)使用 git log --find-object
到 identify commits。
这很好用,我之前使用 git hash-object
但是,当我为同一个文件发出 git hash-object
时, 并且我设置了 core.autocrlf=true
,我得到了一个不同的 blob(散列值) .
因此 git log --find-object
没有识别对应于那个 'new' blob 的提交。
这里发生了什么?这是否意味着 git hash-object
在 core.autocrlf=true
时不 'work'?
将文件写入数据库时,core.autocrlf
告诉 git
对所有输入文件进行 运行 过滤器,将 CRLF 行结尾转换为 LF。它必须在计算 blob 的哈希之前执行此操作,因为根据定义,您更改的每个字节都会影响哈希。
由于 git hash-object
是用于执行此操作的管道命令,因此它也必须执行这些过滤器。如果你想抑制它,并在没有过滤器 运行 的情况下找到文件的哈希值,你可以使用 --no-filters
选项。 Manual summary:
--no-filters
Hash the contents as is, ignoring any input filter that would have been chosen by the attributes mechanism, including the end-of-line conversion. If the file is read from standard input then this is always implied, unless the --path option is given.