Problem: You are about to commit a change in minified, one-liner JSON file and want to see the diff.
Requirements:
- Node.js - if you're not a JS guy, you'll need to write the
pretty_json
file (see below) in language of your choice - (Optional) colordiff - or any other tool to colorize your diffs
Here's my unix/mac solution:
- Copy the
pretty_json
file to some directory that is in yourPATH
. - If you're a vim enthusiast, copy the
vimdiff_json
to the same directory as thepretty_json
file. - Otherwise, copy the
diff_json
to the same directory. Or why not copy both? - Run the following commands:
cd <that_directory_you_copied_files_to> chmod +x pretty_json diff_json vimdiff_json git config --global difftool.diff_json.cmd "diff_json \$LOCAL \$REMOTE" git config --global difftool.vimdiff_json.cmd "vimdiff_json \$LOCAL \$REMOTE" git config --global difftool.prompt false
- You're probably all set (unless I missed something)
Now you can git diff your json file this way:
git difftool ./relative_path/to.json --tool vimdiff_json
# or replace vimdiff_json with diff_json above if you're not into vim
Important note: To exit vim diff, press Esc, then type
qa!
and press Enter.