Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique identifier for file in Git Repository

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.

like image 1000
user1289984 Avatar asked Oct 25 '25 20:10

user1289984


1 Answers

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

like image 160
torek Avatar answered Oct 28 '25 10:10

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!