Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git repository unique id

I need to find out if a commit belongs to a particular git repository.

The idea is to generate some unique id for every repository I need to test. Then I can compare this unique id to the id, calculated from tested commit.

For example take an SHA of initial change set. Can it uniqely identify the repository?

like image 377
Ilya Ivanov Avatar asked Feb 14 '11 14:02

Ilya Ivanov


2 Answers

The SHA1 key is about identifying the content (of a blob, or of a tree), not about a repository.
If the content differ from repo to repo, then its history has no common ancestor, so I don't think a change-set-based solution will work.

Maybe (not tested) you could add some marker (without having to change all the SHA1) through git notes.
See for instance GitHub deploy-notes which uses this mechanism to track deployments.

like image 114
VonC Avatar answered Sep 18 '22 10:09

VonC


(moved from comment)

That's not possible if you don't have the parent of the particular commit already in your repository (in which case you can trivially answer the question). While the commit holds a reference to the parent and maintains the whole tree's integrity that way, you cannot reconstruct a commit just from the hash if you don't have that commit, so you can't find out that parent's parent and so on until you find a parent which actually is within your repository.

like image 39
poke Avatar answered Sep 20 '22 10:09

poke