How to compare the working tree with a commit?

后端 未结 3 1089
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 02:47

I\'m using

git diff mycommit

for comparing my working tree with mycommit, but it seems to ignore files not present in the current

3条回答
  •  庸人自扰
    2021-01-30 02:59

    manojlds wrote in his answer

    Basically, diff does not take into account untracked files. That is why you see that the file is deleted, because the diff is same as git diff B A

    This is true and worth upvoting, but it didn't satisfy me, as it says neither "how can I compare it" not gave it the deeper reason behind. 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:

    The definition of paths in the working tree in these sentences is not "all files on the filesystem", or "all files on the filesystem, filtered with the ignore mechanism". It is "all files on the filesystem that are in the index" ...

    and

    ...that will give a clean semantics to "git diff HEAD": what change would I be recording if I said "git commit -a" at this point?

提交回复
热议问题