Search code examples
pythongitgit-commitgitpython

git commit miss, can't get it


I clone the 'Apache/tomcat' git repo to use some info about commit.

However, when i use git.repo('repo local address').iter_commits(), i can't get some commits. Besides, I can't search these in github search engine.

For example, commit 69c56080fb3355507e1b55d014ec0ee6767a6150 is in the 'Apache tomcat' repo, however, search '69c56080fb3355507e1b55d014ec0ee6767a6150' in 'in this repository' get nothing. It's amazing for me.

It seems like that the commit isn't in the master branch, so can't be searched?

I want to know the theory behind this and how to get info about these 'missing' commits in Python.

Thanks.


Solution

  • repo.iter_commits(), with no arguments, gives you the commits which can be reached by tracing back through the parent(s) of the current commit. In other words, if you are in the master branch, it will only give you commits that are part of the master branch.

    You can give it a rev argument which, among other things, can be a branch name. For example, iter_commits(rev='8.5.x') ought to give you all commits in the 8.5.x branch, which will include 69c5608. You can use another function, repo.branches(), if you need to get a list of branches.

    Alternatively, if you already know the hash of a single commit that you want to look up, you can use repo.commit(), again with a rev parameter which in this case is the full or abbreviated commit hash: commit(rev='69c5608').