2015-03-02 126 views
3

我正在使用gitpython庫執行git操作,從python代碼中檢索git信息。我想檢索特定文件的所有修訂。但是在docs找不到具體的參考。獲取gitpython中的特定文件的所有修訂

任何人都可以提供一些線索,哪些功能在這方面會有所幫助嗎?謝謝。

+1

我不這麼認爲,作爲參照的問題,不涉及gitpython可言。 – Byron 2015-03-02 08:39:37

回答

4

有沒有這樣的功能,但它很容易實現:

import git 
repo = git.Repo() 
path = "dir/file_you_are_looking_for" 

commits_touching_path = list(repo.iter_commits(paths=path)) 

性能將是即使多條路徑參與適中。基準和更多關於can be found in an issue on github的代碼。

2

一個後續,讀取每個文件:

import git 
repo = git.Repo() 
path = "file_you_are_looking_for" 

revlist = (
    (commit, (commit.tree/path).data_stream.read()) 
    for commit in repo.iter_commits(paths=path) 
) 

for commit, filecontents in revlist: 
    ... 
相關問題