I need to get the output of a git log command formatted as JSON. I like the approach suggested in Git log output to XML, JSON, or YAML? to use a custom git log pretty formatter and a light layer of perl processing on top using the command here :
git log \
--pretty=format:'{%n "commit": "%H",%n "author": "%an <%ae>",%n "date": "%ad",%n "message": "%f"%n},' \
$@ | \
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
perl -pe 's/},]/}]/'
This works fantastic for getting those certain fields, but I also need the list of files changed that is returned from using the --name-status flag included in the JSON output.
I've tried various approaches but I'm at a loss at how to approach this. My gut tells me I'm missing something obvious. Any ideas?
Thanks!
I've added --name-only
parameter support to the original Noah Sussman's script so you can get the list of changed files using this command:
git log2json --name-only
The amended script is here .
I know little about Perl. Here is my way to get the changed files of a commit. Hope it helps.
git log -1 <sha1> --pretty=%h --name-only | tail -n +3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.