2017-02-14 78 views
1

我試圖用git複製Subversion的$Id: $功能。我知道我可以使用.gitattributes來設置ident屬性,這將允許我在源代碼註釋中嵌入blob ID。這是基本要求,並且我已被覆蓋。git:如何從blob ID查找文件歷史記錄

但我正在努力研究如何讓ID在實際意義上有用。 git loggit blame需要一個文件名,所以我不能使用它們的ID。 git show只顯示blob內容,但不提供任何鏈接到提交。

我想要的是,給定一個blob ID,以獲得創建該blob的提交。 (最終,要獲得文件的git loggit blame數據,或者能夠檢出包含該文件的修訂版)。我很欣賞像git這樣的分佈式系統中的提交歷史比顛覆更復雜,但是如果我能以任何東西爲出發點,那就足夠了。我真正需要的是能夠證明給定源代碼,我可以追溯到版本控制歷史。

+0

https://stackoverflow.com/questions/39601215/finding-a-file-by-its-corresponding-blobs-hash-in-a-git-repository HTTPS: //stackoverflow.com/questions/33211914/how-to-find-all-uses-of-a-blob-in-a-git-repo https://stackoverflow.com/questions/223678/which-commit-has - 這個二進制大對象 –

回答

0

除了BLOB ID,該gitattributes手冊介紹的export-subst過濾器,所以你可以把那並使用$Format:%H$添加提交哈希,或$Format:%d$包括分支/標籤名稱。您將不得不使用git archive發佈這些文件。

例如:

$ cat .gitattributes 
* export-subst ident 
$ cat foo.c 
// Blob hash: $Id$ 
// Commit hash: $Format:%H%d$ 
$ git archive master | tar -xO 
* export-subst ident 
// Blob hash: $Id: 9e0569a55a4eaacdf8d100a2c3d3654cf767650b $ 
// Commit hash: 3802b7884faf182ce0994ac9d94925dad375be05 (HEAD -> master, tag: v2) 
相關問題