Skip to content

Instantly share code, notes, and snippets.

@Ricket
Created September 25, 2018 16:54
Show Gist options
  • Save Ricket/78bcd681db86bcbb134558428c4c6cb4 to your computer and use it in GitHub Desktop.
Save Ricket/78bcd681db86bcbb134558428c4c6cb4 to your computer and use it in GitHub Desktop.
git diff -- use jq to pretty-print the json before diffing it
echo "*.json diff=json" >> ~/.gitattributes
git config --global core.attributesfile ~/.gitattributes
git config --global diff.json.textconv "jq '.' \$1"
@triplef
Copy link

triplef commented Aug 19, 2021

textconv already adds the filename as a parameter, so the $1 is not needed and results in the JSON being printed twice. The following should work fine (adding --sort-keys for reproducible diffs):

git config --global diff.json.textconv "jq --sort-keys ."

@senhalil
Copy link

senhalil commented Feb 1, 2022

For those who need faster json parsing because of commits with many json files, I suggest json_xs instead of jq.

https://gist.github.com/senhalil/fd5e06913523cb9d45b3123ebd186573?permalink_comment_id=4049199#gistcomment-4049199

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