Question

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.

Était-ce utile?

La solution

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top