I have composer.json files on two different branches and I want to compare their (non-dev) dependencies. This is the command I run to compare the require section of composer.json on my current branch to the require section of composer.json on the branch env_qa.
diff <(jq --sort-keys '.require' composer.json) <(git show env_qa:composer.json | jq --sort-keys '.require')
I’m using jq to extract the dependencies under the require key in composer.json.
Alias
Adding the following function to my .zshrc configuration
function jqgcdiff() {
diff <(jq --sort-keys '.require' composer.json) <(git show "$1":composer.json | jq --sort-keys '.require')
}
allows me to compare the .require section of composer.json on the current branch to the branch I provide as an argument to the function.
e.g.
jqgcdiff main
will compare the .require section of the composer.json file on the current Git branch to the .require section of the composer.json file on the main branch.
The name comes from jq, g for Git, c for Composer, and diff: jqgcdiff.
Excellent tip! This is gonna come in super useful. But even more so, learning about jq for the first time. Adding to my toolbox.