我需要遍历整个仓库的分支提交。我已经尝试过了,但是没有成功。 :
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)
谢谢您的任何帮助。
答案 0 :(得分: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)
从中扩展应该相对容易。我所做的是从提交中包含的文件中收集统计信息。