About git-diff
- From
- Luiz Ramos <luizzramos@yahoo.com.br>
- Date
- Aug 10, 2011, 01:52 UTC
- Message-ID
- <1312941177.17928.YahooMailClassic@web121810.mail.ne1.yahoo.com>
Hello,
just a doubt, but it can also be a bug.
Suppose there is a project stored in git, and it has two branches. In the branch b1, there is a single file, file_1. In the branch b2, there is a single file file_2.
Suppose also I am using branch b1 above (that is, "git checkout b1" was previously run), but the file file_2 was left in the working directory along with file_1.
If I run:
$ git diff --cached b2 ./
The results will point that the file file_1 is added, as it is in the index and not in the tree b2. It will also point that file file_2 is removed, as it is listed in the tree b2, but not in the index. No doubts here.
If I run:
$ git diff b2 ./
that is, the "non-cached" version, it will show the same results. This is confusing IMHO, because the git-diff manual suggests that invocation should render the difference between the named tree contents and the working directory. In the working directory, only to recall, file_1 and file_2 are both present and with good versions. In my understanding, the command should report that file_1 is in excess in the working directory, relative to b2, and report nothing about file_2, as it is in the same version as the sample in the tree b2.
This doesn't seem to be the same thing git-diff-index manual states, however. The manual gets more deep into the details, and it's not so easy to understand it unless one knows a lot of the inner commands, which does not apply to me. In my basic reading, it seems that behind the scenes, git-diff-index is what is run in this case, and the fact that file_2 is not in the tree associated to b1 is a relevant thing in this case. So, the index seem to matter, and if I try to do it, a previous "git update-index" should be done.
I may be wrong, but as a user, I'd like to have the non-cached command version comparing tree and working directory, as the manual of git-diff suggests, eventually helped by the index, but not limited to it. Because if I'd like to compare with index, I would try it using --cached instead.
Please accept my apologies if there is some newbie mistake here.
Thanks,
Luiz Ramos São Paulo - Brazil