0

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!

Community
  • 1
  • 1

2 Answers2

1

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.

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40
0

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
ElpieKay
  • 27,194
  • 6
  • 32
  • 53