List all git commits with GitPython

I am getting ready to do some timeseries analysis on a git repo with python, my first step is to figure out a way to list all of the git commits so that I can analyze each one however I want. The GitPython library made this almost trivial once I reali…


This content originally appeared on DEV Community and was authored by Waylon Walker

I am getting ready to do some timeseries analysis on a git repo with python, my first step is to figure out a way to list all of the git commits so that I can analyze each one however I want. The GitPython library made this almost trivial once I realized how.

from git import Repo

repo = Repo('.') commits = repo.iter_commits()

This returns a generator, if you are iterating over them this is likely what you want.

commits
# <generator object Commit._iter_from_process_or_stream at 0x7f3307584510>

The generator will return git.Commit objects with lots of information about each commit such as hexsha, author, commited_datetime, gpgsig, and
message.

next(commits)
# <git.Commit "d125317892d0fab10a36638a2d23356ba25c5621">


This content originally appeared on DEV Community and was authored by Waylon Walker


Print Share Comment Cite Upload Translate Updates
APA

Waylon Walker | Sciencx (2022-05-09T21:08:10+00:00) List all git commits with GitPython. Retrieved from https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/

MLA
" » List all git commits with GitPython." Waylon Walker | Sciencx - Monday May 9, 2022, https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/
HARVARD
Waylon Walker | Sciencx Monday May 9, 2022 » List all git commits with GitPython., viewed ,<https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/>
VANCOUVER
Waylon Walker | Sciencx - » List all git commits with GitPython. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/
CHICAGO
" » List all git commits with GitPython." Waylon Walker | Sciencx - Accessed . https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/
IEEE
" » List all git commits with GitPython." Waylon Walker | Sciencx [Online]. Available: https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/. [Accessed: ]
rf:citation
» List all git commits with GitPython | Waylon Walker | Sciencx | https://www.scien.cx/2022/05/09/list-all-git-commits-with-gitpython/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.