2

我需要遍历整个 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)

任何帮助将不胜感激,谢谢。

4

1 回答 1

0

这就是我所拥有的:

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)

从那里扩展应该相对容易。我所做的是从提交中包含的文件中收集统计信息。

于 2021-07-21T12:21:01.113 回答