簡體   English   中英

Pygit2:需要關於如何處理所有 repo 分支中的所有提交的幫助

[英]Pygit2: Need help on how to walk on all commits in all repo's branches

我需要遍歷整個 repo 的分支提交。 我試過這個,但沒有成功。

for branch_name in list(repo.branches.remote):
   try:
        branch = repo.lookup_branch(branch_name)
        ref = repo.lookup_reference(branch.name)
        repo.checkout(ref)

        for commit in repo.walk(branch.target, pygit2.GIT_SORT_TIME):
            print(commit.id.hex)

任何幫助將不勝感激,謝謝。

這就是我所擁有的:

def iterate_repository(dir: str) -> None:
    repo = pygit2.Repository(dir)
    for branch_name in list(repo.branches.remote):
        branch = repo.branches.get(branch_name)
        latest_commit_id = branch.target
        latest_commit = repo.revparse_single(latest_commit_id.hex)

        for commit in repo.walk(latest_commit.id, pygit2.GIT_SORT_TIME):
            print(commit.id.hex)

從中擴展應該相對容易。 我所做的是從提交中包含的文件中收集統計信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM