Skip to content

Instantly share code, notes, and snippets.

@signed0
Last active December 16, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save signed0/5456882 to your computer and use it in GitHub Desktop.
Save signed0/5456882 to your computer and use it in GitHub Desktop.
Determine the first and last commit date for each user in a git repo.
import datetime
from collections import defaultdict
import subprocess
def main():
git_log = subprocess.check_output(['git', 'log', "--pretty=format:%an\t%ct"])
users = defaultdict(list)
for line in git_log.split('\n'):
name, commit_time = line.strip().split('\t')
commit_time = datetime.datetime.fromtimestamp(int(commit_time))
users[name].append(commit_time)
print '\t'.join(('User', 'First Commit', 'Last Commit', 'Count'))
for name, dates in sorted(users.iteritems(), key=lambda x:x[0]):
start, end = min(dates), max(dates)
parts = (name, start, end, len(dates))
print '\t'.join(str(s) for s in parts)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment