Created
May 22, 2025 12:45
-
-
Save jelleroorda/8bd10b6ddf10ec18333186e8a105e197 to your computer and use it in GitHub Desktop.
First commit, last commit, commit count for every user in the current git repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import datetime | |
| from collections import defaultdict | |
| import subprocess | |
| def main(): | |
| git_log = subprocess.check_output(['git', 'log', "--pretty=format:%an\t%ct"]).decode('utf-8') | |
| users = defaultdict(list) | |
| for line in git_log.split('\n'): | |
| if line.strip(): | |
| name, commit_time = line.strip().split('\t') | |
| commit_time = datetime.datetime.fromtimestamp(int(commit_time)) | |
| users[name].append(commit_time) | |
| header = ('User', 'First Commit', 'Last Commit', 'Count') | |
| max_widths = [len(header[i]) for i in range(len(header))] | |
| for name, dates in sorted(users.items(), key=lambda x: x[0]): | |
| start, end = min(dates), max(dates) | |
| parts = (name, start.strftime('%Y-%m-%d %H:%M:%S'), end.strftime('%Y-%m-%d %H:%M:%S'), len(dates)) | |
| for i, part in enumerate(parts): | |
| max_widths[i] = max(max_widths[i], len(str(part))) | |
| formatted_header = '\t'.join(f"{header[i]:<{max_widths[i]}}" for i in range(len(header))) | |
| print(formatted_header) | |
| for name, dates in sorted(users.items(), key=lambda x: min(x[1])): | |
| start, end = min(dates), max(dates) | |
| parts = (name, start.strftime('%Y-%m-%d %H:%M:%S'), end.strftime('%Y-%m-%d %H:%M:%S'), len(dates)) | |
| formatted_row = '\t'.join(f"{str(parts[i]):<{max_widths[i]}}" for i in range(len(parts))) | |
| print(formatted_row) | |
| if __name__ == '__main__': | |
| main() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./commit-info