Last active
August 28, 2024 14:40
-
-
Save oscherler/22eb60eb78a4e4e89e0506578e8b820a to your computer and use it in GitHub Desktop.
Revisions
-
oscherler revised this gist
Aug 15, 2017 . No changes.There are no files selected for viewing
-
oscherler revised this gist
Aug 15, 2017 . 2 changed files with 27 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,25 @@ # jsondiff: diff JSON in Git using gron [`gron`](https://github.com/tomnomnom/gron) is an incredible tool that makes JSON greppable. But it also makes it diffable, which is great if you have JSON files in Git. To use `gron` to diff JSON in Git, save the `json-diff` script below and make it executable. Then add a difftool as shown in `gitconfig`, and optionally create an alias to invoke it more easily. Then try it: ``` git init echo '{"foo":42,"bar":"hello"}' > foo.json git add foo.json && git commit -m 'Initial commit.' echo '{"foo":43,"bar":"hello"}' > foo.json git jdiff ``` will give you: ```diff --- a/foo.json +++ b/foo.json @@ -1,3 +1,3 @@ json = {}; json.bar = "hello"; -json.foo = 42; +json.foo = 43; ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ [difftool "jsondiff"] cmd = "/path/to/json-diff $LOCAL $REMOTE" [alias] jdiff = difftool -t jsondiff -y -
oscherler renamed this gist
Aug 15, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ [alias] jdiff = difftool -t jsondiff -y [difftool "jsondiff"] cmd = "/path/to/json-diff $LOCAL $REMOTE" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # jsondiff: diff JSON in Git using gron [`gron`](https://github.com/tomnomnom/gron) is an incredible tool that makes JSON greppable. But it also makes it diffable,which is great if you have JSON files in Git. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/zsh # gron: https://github.com/tomnomnom/gron GRON=/usr/local/bin/gron DIFF=/usr/bin/diff # colordiff: https://www.colordiff.org COLORDIFF=/usr/bin/colordiff # use colordiff in interactive mode, diff otherwise if [ -t 1 ] then DIFFER=${COLORDIFF} else DIFFER=${DIFF} fi LOCAL="$1" REMOTE="$2" "${DIFFER}" -u --label "a/$REMOTE" --label "b/$REMOTE" <( "$GRON" < "$LOCAL" ) <( "$GRON" < "$REMOTE" ) | less