GIT 中的“提交 ID”和“SHA1 哈希”有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43763896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:44:17  来源:igfitidea点击:

What's the difference between 'Commit ID' and 'SHA1 Hash' in GIT?

gitcryptography

提问by Sathish Kumar

I've been working on GIT for quite sometime now.

我已经在 GIT 上工作了一段时间。

However, I could not find difference between 'Commit Id' and 'SHA1 - hash value'

但是,我找不到“提交 ID”和“SHA1 - 哈希值”之间的区别

What is the difference between 'Commit ID' and 'SHA1'? Any simple explanation with an example would be nice

“提交 ID”和“SHA1”有什么区别?任何带有示例的简单解释都会很好

回答by Eduardo Dennis

Commit ID is what identifies a commit. Sometimes you will see the shorthand version which is just the first seven characters of the actual commit ID versus the full hash.

提交 ID 用于标识提交。有时您会看到简写版本,它只是实际提交 ID 与完整哈希的前七个字符。

Consider the following example:

考虑以下示例:

`[master 42e2e5a] Added a new readme file to illustrate commit IDs.
1 file changed, 1 insertion(+)
create mode 100644 myreadme

notice it is showing the shorthand version of the commit ID. Because the actual commit ID is forty hexadecimal characters that specify a 160-bit SHA-1 hash.

请注意,它显示了提交 ID 的速记版本。因为实际提交 ID 是 40 个十六进制字符,用于指定 160 位 SHA-1 哈希。



Example

例子

Full commit ID

完整提交 ID

 git show -s --format=%H

Result

结果

42e2e5af9d49de268cd1fda3587788da4ace418a

Shorthand version

速记版

  git show -s --format=%h

Result

结果

42e2e5a

But notice they are the same.

但请注意,它们是相同的。

回答by eftshift0

I've read the answers provided before and I think there's a little thing to add to them. A revision always pointsto a sha1 (it doesn't actually point, a revision is identifiedby its sha1 ID but bear with me) but objects in git's DB can be: revisions, trees, blobs, etc and they are all identified by sha1 IDs. So a revision implies using a sha1 ID (to identify it... but there are other sha1 IDs used in a revision like for parents, tree object) but a sha1 ID doesn't necessarily mean it's a revision.

我已经阅读了之前提供的答案,我认为有一些东西要添加到它们中。的修订总是指向一个SHA1(它实际上没有点,修订鉴定其SHA1 ID,但忍耐一下),但在Git的数据库对象可以是:修改,树木,斑点等,它们都是由SHA1鉴定身件。因此,修订意味着使用 sha1 ID(来识别它……但在修订中还使用了其他 sha1 ID,例如父级、树对象),但 sha1 ID 并不一定意味着它是修订。