How to compare the working tree with a commit?

后端 未结 3 1088
被撕碎了的回忆
被撕碎了的回忆 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 03:23

    The question is: I have added some file in my working tree, that exists in the other commit. Why is git diff not showing me the difference between the file content that exists in my working tree and the content of the file that is in the other commit.

    This is because the new file that you added is untracked and hence, well, git doesn't track it.

    Try git diff HEAD you won't see that you have added B.txt in your working tree.

    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

    Now, if you were to add the file, you will see the expected result, because git is tracking it now.

    Say, you committed the file and then modify the content in the working tree:

    Now, git diff HEAD will show the difference between working tree and HEAD, showing the change you have done in your working tree on tracked files. Same with git diff B

提交回复
热议问题