這三大部分中:
working tree:就是你所工作在的目錄挡篓,每當(dāng)你在代碼中進(jìn)行了修改帚称,working tree的狀態(tài)就改變了。
index file:是索引文件戏羽,它是連接working tree和commit的橋梁,每當(dāng)我們使用git-add命令來登記后始花,index file的內(nèi)容就改變了,此時(shí)index file就和working tree同步了酷宵。
commit:是最后的階段,只有commit了炕置,我們的代碼才真正進(jìn)入了git倉庫。我們使用git-commit就是將index file里的內(nèi)容提交到commit中讹俊。
總結(jié)一下:
git diff:是查看working tree與index file的差別的煌抒。
git diff --cached:是查看index file與commit的差別的。
git diff HEAD:是查看working tree和commit的差別的贩疙。(你一定沒有忘記况既,HEAD代表的是最近的一次commit的信息)
為了更加清晰的闡釋這個(gè)關(guān)系,來給出一個(gè)實(shí)例棒仍。
[yaya@yaya-desktop]$ cat main.c
#include
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
int main(int argc,char *argv[])
{
printf(“hello.\n”);
printf(“he was a student.\n”);
printf(“he was born in finland.\n”);
return 0;
}
此時(shí)你git add .,但不用執(zhí)行g(shù)it commit命令癞尚。然后你再將源代碼改為:
[yaya@yaya-desktop]$ cat main.c
#include
int main(int argc,char *argv[])
{
printf(“hello.\n”);
printf(“he was a student.\n”);
printf(“he was born in finland.\n”);
printf(“he is very clever!\n”);
return 0;
}
復(fù)制代碼
這個(gè)時(shí)候乱陡,你執(zhí)行如下三個(gè)命令,仔細(xì)查看胳徽,我相信你會(huì)發(fā)現(xiàn)它們?nèi)齻€(gè)的區(qū)別的爽彤!
$ git diff
$ git diff –cached
$ git diff HEAD
講到這里,基本上對(duì)git diff命令有了比較深入的了解了淫茵,現(xiàn)在你再使用git status看看輸出結(jié)果,樣子大概是這樣:
[yaya@yaya-desktop]$ git status
# On branch master
# Changes to be committed:
# ? (use “git reset HEAD …” to unstage)
#
# ? ?modified: ? main.c
#
# Changed but not updated:
# ? (use “git add …” to update what will be committed)
#
# ? ?modified: ? main.c
#很明顯可以知道:
Changes to be committed表示已經(jīng)存在于index file里铆铆,但尚未提交蝶缀。
Changed but not updated表示在working tree已經(jīng)做修改翁都,但還沒有使用git add登記到index file里谅猾。
好了,對(duì)于git diff的用法就簡單溫習(xí)到這里吧税娜。