I want to perform a comparison operation between a file which exists on disk and a file which no longer exists because I moved it.
Here's the situation.
./src/A.txt
.A.txt
to a new folder. It's now called ./doc/A.txt
../doc/A.txt
.I now want to compare ./doc/A.txt
with the state of ./src/A.txt
which exists on the branch origin/main
. Of course, this file does not actually exist in the current working directory.
I think one possible way to do this might be to do the following:
git checkout origin/main ./src/A.txt
git diff ./src/A.txt ./doc/A.txt
(Edit: Nope - this doesn't work. Use diff ./src/A.txt ./doc/A.txt
instead.)
Is there a way to do it "directly"?
Maybe something like
git diff ./src/A.txt@origin/main ./doc/A.txt
You can get what you want with:
git show origin/main:./src/A.txt | diff - doc/A.txt
or
git diff origin/main:./src/A.txt doc/A.txt