0

I can compare two remote files with diff and ssh:

diff <(ssh machine1 "sudo cat ${FILE}") <(ssh machine2 "sudo cat ${FILE}")

but if I try with git diff,

git diff --no-index --color-words <(ssh machine1 "sudo cat ${FILE}") <(ssh machine2 "sudo cat ${FILE}")

I obtain:

error: /dev/fd/14: unsupported file type
fatal: cannot hash /dev/fd/14

How can I, with git diff, compare two remote files not in a repository ?

== Update ==

This question is not about substituting git diff by diff and colordiff, but about using git diff --no-index through ssh.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240

2 Answers2

2

Since process substitution cannot be used because of a forgotten patch, the only option (since you want to use git diff) is :

ssh machine1 "sudo cat ${FILE}" > temp1 
ssh machine2 "sudo cat ${FILE}" > temp2
git diff --no-index temp1 temp2

You can achieve the same using diff (it maintains formatting and colors similar to git diff) which works with process substitution too

diff -u --color <(ssh machine1 "sudo cat ${FILE}") <(ssh machine2 "sudo cat ${FILE}")
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • @OrtomalaLokni `&&` indicates that the second ssh command will run only if the first one completes successfully. However, it is not required in this case and I have edited it. Regarding process substitution, [this](https://stackoverflow.com/q/22706714/10155936) explains it clearly – Saurabh P Bhandari Apr 20 '20 at 16:59
0

Try using

git diff --no-index <(ssh machine1 "sudo cat ${FILE}") <(ssh machine2 "sudo cat ${FILE}")

As found here.

wederer
  • 550
  • 2
  • 5
  • 17