Skip to content

Instantly share code, notes, and snippets.

@NGenetzky
Forked from varemenos/1.README.md
Last active January 25, 2023 02:06
Show Gist options
  • Save NGenetzky/46621b35d60fed8f036311c6f1637e48 to your computer and use it in GitHub Desktop.
Save NGenetzky/46621b35d60fed8f036311c6f1637e48 to your computer and use it in GitHub Desktop.
Git log as JSON array

Git log as JSON array

git log \
  --pretty=format:'{^^^^date^^^^:^^^^%ci^^^^,^^^^abbreviated_commit^^^^:^^^^%h^^^^,^^^^subject^^^^:^^^^%s^^^^,^^^^body^^^^:^^^^%b^^^^}' \
  | sed 's/"/\\"/g' \
  | sed 's/\^^^^/"/g' \
  | jq -s '.'

The format is applied to each line to create a json object per line. Then jq --slurp is used to "slurp" up the objects to create a valid json array object.

git log pretty format source: http://git-scm.com/docs/pretty-formats

Credit:

#!/bin/sh
# [Git log as JSON array](https://gist.github.com/NGenetzky/46621b35d60fed8f036311c6f1637e48)
git log --pretty=format:'{^^^^date^^^^:^^^^%ci^^^^,^^^^abbreviated_commit^^^^:^^^^%h^^^^,^^^^subject^^^^:^^^^%s^^^^,^^^^body^^^^:^^^^%b^^^^}' | sed 's/"/\\"/g' | sed 's/\^^^^/"/g' | jq -s '.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment