我有3个文件,A,B,C。
我对A和B进行了一些更改,然后运行git diff
来检查我所做的更改。一切都很好看。然后我对“C”进行了更改并再次运行git diff
,但这次只显示了我对“C”所做的更改。如果我输入git diff HEAD
,那么我可以看到对所有3个文件的更改。
我犯的时候会发生什么?它只会改变C或A,B,C吗?
答案 0 :(得分:2)
如果git add
将A和B编入索引,则可以git diff --cached
查看其更改。 git diff
仅显示未分阶段的更改。请git diff man page:
Various ways to check your working tree
$ git diff (1)
$ git diff --cached (2)
$ git diff HEAD (3)
1. Changes in the working tree not yet staged for the next commit.
2. Changes between the index and your last commit; what you would be committing
if you run "git commit" without "-a" option.
3. Changes in the working tree since your last commit; what you would be
committing if you run "git commit -a"
最终,您应该在提交之前使用git status
,以确定您将要提交的内容。
答案 1 :(得分:1)
您通过git add
添加了A和B.如果在为下次提交暂存filex后运行git diff
,则不会看到更改。这是预期的行为,您可以运行git diff --cached
来查看对添加的文件的更改。
如果您修改另一个文件,C,git diff
将仅显示C中的更改(尚未暂停)。
命令git diff HEAD
显示了分阶段和非分阶段文件的更改:确切地说,它显示了自上次提交以来工作树中的更改。
要简要回答原始问题,git commit
会将更改提交给您修改的所有文件(A,B,C),而不仅仅是C.