Skip to content

Instantly share code, notes, and snippets.

@cekstam
Last active December 27, 2021 14:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cekstam/a7758b8f315835d479f379715eebd0c3 to your computer and use it in GitHub Desktop.
Save cekstam/a7758b8f315835d479f379715eebd0c3 to your computer and use it in GitHub Desktop.
create valid JSON from git log using python and ast.literal_string
git log -n 10\
--pretty=format:'{"commit": "%H", "author": "%aN <%aE>", "date": "%ai", "message": """%B""", "notes": """%N""" },' \
$@ | awk 'BEGIN { print("[") } { print($0) } END { print("]") }' | python -u -c \
'import ast,json,sys; print(json.dumps(ast.literal_eval(sys.stdin.read())))'
@fi3ework
Copy link

fi3ework commented Jul 24, 2020

This script is awesome. Thanks.

@yashika51
Copy link

Hi @cekstam, is there a way we can run this to get json for all the commits without mentioning the number like -n 10?
If I remove the -n I get errors and no output. Thanks!

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