显然相同的提交给不同的sha1,为什么? [英] apparently same commits give different sha1, why?

查看:186
本文介绍了显然相同的提交给不同的sha1,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的脚本重新编写一个存储库中的子树历史记录后,我将它与 git filter-branch ... 同一子树。我发现初始提交有不同的sha1,但我期望它们是相同的(因为这两个历史记录中的所有提交都有不同的sha1)。



执行<$在两次提交中,c $ c> git show --format = raw< commit-sha1> 给出了完全相同的输出(除了第一行, commit&commit -sha1> ,介绍结果)。

目标文件完全不同,但由于它们是二进制文件,我无法弄清楚根本原因。



假设所有git版本相互一致,有什么可以解释为有2个不同的sha1?



谢谢

解决方案

Git对提交散列的输入包括元数据,如树的SHA1,父代的SHA1 ,提交者的姓名,电子邮件和提交日期以及作者姓名,电子邮件和提交日期。所以当你重写历史记录时,提交者提交日期和树(因为你做了一个 filter-branch )可能已经改变了,所以你的提交的SHA1有所不同。



有关提交格式的更多信息,您可以使用 git cat-file commit< sha> 了解Git Book的 Git Objects部分


After re-write of a subtree history from a repository with a script of mine, I compared it with what would do a git filter-branch ... on that same subtree. I see that initial commits have different sha1 although I expected them to be identical (consequence of this is that all commits from both histories have different sha1).

Doing a git show --format=raw <commit-sha1> on both commits gives exactly the same output (except for first line, which is commit <commit-sha1>, introducing the result).

Object files are completely different, but as they are binaries, I can't figure out the root cause.

Assuming all git versions are consistent with each other, what could explain to have 2 different sha1?

Thank you

解决方案

Git's inputs to a commit hash include metadata such as the SHA1 of the tree, the SHA1 of the parent, the commiter's name, email and commit date, and the author's name, email and commit date. So when you rewrote history, the commiter commit date and the tree (since you did a filter-branch) have probably changed, hence the difference in your commit's SHA1.

For more information about the format of a commit, you can use git cat-file commit <sha>, or look up the Git Objects section of the Git Book.

这篇关于显然相同的提交给不同的sha1,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆