git diff的用法_patch git binary diffs are not supported.
作者:Monodyee | 2024-05-12 15:22:31
赞
踩
patch git binary diffs are not supported.
在git提交环节,存在三大部分:working tree, index file, commit
这三大部分中: working tree:就是你所工作在的目录,每当你在代码中进行了修改,workingtree的状态就改变了。
index file:是索引文件,它是连接workingtree和commit的桥梁,每当我们使用git-add命令来登记后,index file的内容就改变了,此时indexfile就和working tree同步了。
commit:是最后的阶段,只有commit了,我们的代码才真正进入了git仓库。我们使用git-commit就是将indexfile里的内容提交到commit中。
总结一下: git diff:是查看working tree与index file的差别的。
git diff --cached:是查看index file与commit的差别的。
git diff HEAD:是查看workingtree和commit的差别的。(你一定没有忘记,HEAD代表的是最近的一次commit的信息)
为了更加清晰的阐释这个关系,来给出一个实例。
[yaya@yaya-desktop]$ cat main.c
#include<stdio.h>
int main(int argc,char *argv[])
{
printf(“hello.\n”);
printf(“he was a student.\n”);
return 0;
}
然后git init, git add . , git commit;
之后你将源代码修改为:
[yaya@yaya-desktop]$ cat main.c
#include<stdio.h>
int main(int argc,char *argv[])
{
printf(“hello.\n”);
printf(“he was a student.\n”);
printf(“he was born in finland.\n”);
return 0;
}
[yaya@yaya-desktop]$ git status
# On branch master
#
Changes to be committed: #
(use “git reset HEAD<file>…” to unstage)
#
#
modified:
main.c
#
#
Changed but not updated: #
(use “git add<file>…” to update what will becommitted)
#
#
modified:
main.c
#很明显可以知道:
Changes to be committed表示已经存在于indexfile里,但尚未提交。
Changed but not updated表示在workingtree已经做修改,但还没有使用git add登记到index file里。