Skip to content

Instantly share code, notes, and snippets.

@scragg0x
Created April 25, 2018 20:59
Show Gist options
  • Save scragg0x/7269b80d8e17c76ef5a9e8a7e22b9bf0 to your computer and use it in GitHub Desktop.
Save scragg0x/7269b80d8e17c76ef5a9e8a7e22b9bf0 to your computer and use it in GitHub Desktop.
Get commit history grouped by tag / user
import argparse
from subprocess import check_output
from datetime import datetime
parser = argparse.ArgumentParser()
parser.add_argument('--dir', default='.', help='Git Directory')
parser.add_argument('--start', help='From Date YYYY-MM-DD')
args = parser.parse_args()
if args.start:
start_date = datetime.strptime(args.start, "%Y-%m-%d")
git_tags_cmd = "git for-each-ref --sort=taggerdate --format '%(refname) %(taggerdate)' refs/tags"
tags = []
for line in check_output(git_tags_cmd, shell=True, cwd=args.dir).strip().split("\n"):
parts = line.split(" ")
name = "".join(parts[0].split("/")[2:])
date = datetime.strptime(" ".join(parts[1:-1]), "%c")
tags.append(dict(name=name, date=date))
for i in range(len(tags)):
if i == 0:
continue
if start_date and start_date > tags[i]['date']:
continue
tags[i]['changes'] = check_output("git shortlog {0} --not {1}".format(tags[i]['name'], tags[i-1]['name']), shell=True, cwd=args.dir)
print("{0} - {1}".format(tags[i]['name'], tags[i]['date'].isoformat()))
print(tags[i]['changes'])
print('---------------------------------------------')
@scragg0x
Copy link
Author

scragg0x commented Apr 25, 2018

python changelog.py --dir /my/git/repo --start 2018-01-01 > changes.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment