Skip to content

Instantly share code, notes, and snippets.

Last active June 7, 2019 14:19
What would you like to do?
Get commits from an author in a time period
from datetime import datetime
from git import Repo
def get_commits_from_author(repo_path, author_term, start_date, end_date):
repo = Repo(repo_path)
start_date, end_date = [
datetime.fromisoformat(d).date() for d in (start_date, end_date)
return [
for commit in repo.iter_commits()
if author_term in
and start_date <= <= end_date
def loc_in_my_commits(*args, **kwargs):
commits = get_commits_from_author(*args, **kwargs)
return sum(["lines"] for commit in commits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment