I’m using
git diff mycommit
for comparing my working tree with mycommit, but it seems to ignore files not present in the current index. You can reproduce it as follows:
git init
echo A > A.txt; git add .; git commit -m A; git branch A
echo B > B.txt; git add .; git commit -m B; git branch B
git reset --hard A
echo BB > B.txt
git diff B
The output (as of git version 1.7.3.3) is empty. Using --diff-filter=ACDMRTUXB shows “deleted file” which is wrong as well, since the file B.txt exists both in the working tree and in commit B. IMHO, the file should be shown as modified. Surprisingly, it works after adding the file to the index, although it’s not the index what gets compared. How can I get the right diff without it?
manojlds wrote in his answer
This is true and worth upvoting, but it didn’t satisfy me, as it says neither "how can I compare it" nor gave the deeper reason behind it. I still thought it was a bug, so I asked at the git forum and got a long answer by somebody who surely knows. The important parts for me are:
and