Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent git from generating false difference for JSON files?

git thinks that two versions of a .json file is different, but actually their data is not:

@@ -469,9 +479,9 @@
       "integrity": "sha1-+GzWzvT1MAyOY+B6TVEvZfv/RTE=",
       "dev": true,
       "requires": {
+        "JSONStream": "1.3.1",
         "combine-source-map": "0.7.2",
         "defined": "1.0.0",
-        "JSONStream": "1.3.1",
         "through2": "2.0.3",
         "umd": "3.0.1"
       }

How can we tell git to ignore such differences for JSON files?

Note:

Following code from Tomasz Wegrzanowski's Blog:

echo "*.json diff=json" >> .gitattributes
git config diff.json.textconv json_pp

is not working and causing hangs on git diff

like image 647
ceremcem Avatar asked Apr 06 '26 19:04

ceremcem


1 Answers

I thing you config hangs cause json_pp doesnt accept the filename as parameter. That means in your config json_pp waits for inputs on std-input stream, and cause you don`t deliver any input streams your git diff hangs In my gitconfig I have implemented json_pp like this:

[diff "json"]
         textconv = "cat \"$1\" | json_pp --json_opt=canonical,pretty" 

For me this works fine. If you like you can change the --json_opt values to have you favorite output-format. But if the order of keys change this config will still show a difference.

Tested in git-version 2.16.1.windows.1

like image 126
Radon8472 Avatar answered Apr 08 '26 14:04

Radon8472



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!