Git存储库中文件的唯一标识符 [英] Unique identifier for file in Git Repository

查看:203
本文介绍了Git存储库中文件的唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git存储库中是否存在文件的唯一标识符?在某些提交(修改文件)之后,或者在重命名和移动文件之后,此唯一标识符必须相同.

Does there exist any unique identifier for files in a Git Repository? This unique identifier must be the same after some commits (modifying files), or after renaming and moving file(s).

这样的东西存在吗?

我尝试了git ls-files --debug,但是没有找到具有上述特征的唯一标识符.

I tried git ls-files --debug but I didn't find a unique identifier with the characteristics listed above.

推荐答案

git仓库中文件("blob")的唯一唯一标识符是其SHA-1,但这是文件内容的校验和(加上它是文件/blob的事实).仅当文件内容保持不变时,它才保持不变.它不取决于文件的名称,但确实取决于其内容,因此修改文件将更改SHA-1.

The only unique identifier for a file ("blob") within a git repo is its SHA-1, but that is a checksum of the file's contents (plus the fact of it being a file/blob). It remains constant only while the file's contents remain unchanged. It does not depend on the file's name, but it does depend on its contents, so modifying the file will change the SHA-1.

您可以组成自己的唯一ID,但是还必须进行自己的跟踪,将ID映射到当前树的相对名称(或git-name,即SHA-1),并在文件更改时进行更改被重命名(或分别修改).

You could make up your own unique ID but you would also have to do your own tracking, mapping the ID to the current tree-relative name (or git-name, i.e., SHA-1) and changing it when the file is renamed (or modified, respectively).

这篇关于Git存储库中文件的唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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