How to compare the working tree with a commit?

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

    A simple graphic might be of help:

    enter image description here

    So there are three types of diff you can ask for:

    1. git diff --cached This is the difference between what is in the index and the last commit. It shows you that changes that will be in the next commit.

    2. git diff This shows the difference in between the index and the working tree. These are the changes that you have made to files since you last added them to the index. This is why I wasn’t getting any results. I had no changes between the index and the working tree.

    3. git diff HEAD This shows the difference between the files in the working tree and the last commit. There is a gotcha here: if you've made changes, added them to the index, and then backed out these changes in the working tree, you’ll get no results for git diff HEAD (because there is no difference) but you will get output for git diff --cached because there are still changes in the index.

    And if you want to compare it against previous commits:

    enter image description here

    This just compares against the previous commits, but you can replace HEAD~ with any other reference to a commit.

提交回复
热议问题