问题描述
我克隆了 'Apache/tomcat' git repo 以使用有关提交的一些信息。
但是,当我使用 git.repo('repo local address').iter_commits()
时,我无法获得一些提交。
另外,我在github搜索引擎中搜索不到这些。
例如,commit 69c56080fb3355507e1b55d014ec0ee6767a6150 在 'Apache tomcat' 存储库中,但是,search '69c56080fb3355507e1b55d014ec0ee6767a6150' in 'in this repository' 什么也得不到。 对我来说太棒了。
好像提交不在master分支,所以搜索不到?
我想知道这背后的理论以及如何在 Python 中获取有关这些“缺失”提交的信息。
谢谢。
解决方法
repo.iter_commits()
不带参数,为您提供可以通过追溯当前提交的父级来访问的提交。换句话说,如果您在 master
分支中,它只会为您提供属于 master
分支的提交。
你可以给它一个 rev
参数,among other things 可以是一个分支名称。例如,iter_commits(rev='8.5.x')
应该为您提供 8.5.x
分支中的所有提交,其中将包括 69c5608
。如果需要获取分支列表,可以使用另一个函数 repo.branches()
。
或者,如果您已经知道要查找的单个提交的哈希值,则可以使用 repo.commit()
,再次使用 rev
参数,在这种情况下是完整或缩写的提交哈希:commit(rev='69c5608')
。
我认为这里的问题是此提交位于分支 8.5.x
而不是 master
。您可以在第一个链接中看到这一点。它将显示哪些分支包含它。 GitHub 搜索算法仅搜索 master
/main
/trunk
分支。
要通过 git
python 库找到它,请尝试更改到该分支。请参阅有关如何切换分支的说明:https://gitpython.readthedocs.io/en/stable/tutorial.html#switching-branches