Unique identifier for file in Git Repository

♀尐吖头ヾ 提交于 2019-12-11 05:54:50

问题


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).

Does such a thing exist?

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


回答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.

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).




回答2:


No, there isn't one. If you modify it, it's a different file from Git's point of view.



来源:https://stackoverflow.com/questions/19122677/unique-identifier-for-file-in-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!