'git: check diff between local working copy and remote working copy

We have to copy over files to an archaic live server for reasons I can't control so I need to see a diff of what the remote working copy will be compared to my local working copy (which is at a different base).

What are the command lines for this? I've tried several things and they either just hang or don't give the output I need.



Solution 1:[1]

Assuming your remote is named as origin and you are trying to compare your local branch named as master with the remote branch named master, first fetch the remote changes using:

git fetch

then compare your local to the remote using:

git diff origin/master

Visit git diff documentation for more info.

Solution 2:[2]

A commit defines the whole contents of the working copy. If both sides checked out the same commit they will show the same contents. (Unless you did some manual changes afterwards.)

If both sides were cloned from the same (central) repository, but use different commits of that (say first_hash and second_hash), you can use git fetch got get all commits of that repository and then do something like git diff first_hash second_hash to see the differences between both versions.

Solution 3:[3]

The way to compare a file in the working directory with uncommitted changes vs a file in a different branch for example the file coming from upstream is as follows.

git diff origin/master:file.txt file.txt

As you can see here we are comparing the file in our working directory and not the one that is on the master branch.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharam Gollapudi
Solution 2 michas
Solution 3 Neto Buenrostro