在git提交环节,存在三大部分:working tree, index file, commit
来源:互联网 发布:数据有效性校验身份证 编辑:程序博客网 时间:2024/06/05 06:54
这三大部分中:
working tree:就是你所工作在的目录,每当你在代码中进行了修改,working tree的状态就改变了。
index file:是索引文件,它是连接working tree和commit的桥梁,每当我们使用git-add命令来登记后,index file的内容就改变了,此时index file就和working tree同步了。
commit:是最后的阶段,只有commit了,我们的代码才真正进入了git仓库。我们使用git-commit就是将index file里的内容提交到commit中。
总结一下:
git diff:是查看working tree与index file的差别的。
git diff --cached:是查看index file与commit的差别的。
git diff HEAD:是查看working tree和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;
}
此时你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”);
printf(“he is very clever!\n”);
return 0;
}
复制代码
这个时候,你执行如下三个命令,仔细查看,我相信你会发现它们三个的区别的!
$ git diff
$ git diff –cached
$ git diff HEAD
讲到这里,基本上对git diff命令有了比较深入的了解了,现在你再使用git status看看输出结果,样子大概是这样:
[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 be committed)
#
# modified: main.c
#很明显可以知道:
Changes to be committed表示已经存在于index file里,但尚未提交。
Changed but not updated表示在working tree已经做修改,但还没有使用git add登记到index file里。
好了,对于git diff的用法就简单温习到这里吧。
working tree:就是你所工作在的目录,每当你在代码中进行了修改,working tree的状态就改变了。
index file:是索引文件,它是连接working tree和commit的桥梁,每当我们使用git-add命令来登记后,index file的内容就改变了,此时index file就和working tree同步了。
commit:是最后的阶段,只有commit了,我们的代码才真正进入了git仓库。我们使用git-commit就是将index file里的内容提交到commit中。
总结一下:
git diff:是查看working tree与index file的差别的。
git diff --cached:是查看index file与commit的差别的。
git diff HEAD:是查看working tree和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;
}
此时你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”);
printf(“he is very clever!\n”);
return 0;
}
复制代码
这个时候,你执行如下三个命令,仔细查看,我相信你会发现它们三个的区别的!
$ git diff
$ git diff –cached
$ git diff HEAD
讲到这里,基本上对git diff命令有了比较深入的了解了,现在你再使用git status看看输出结果,样子大概是这样:
[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 be committed)
#
# modified: main.c
#很明显可以知道:
Changes to be committed表示已经存在于index file里,但尚未提交。
Changed but not updated表示在working tree已经做修改,但还没有使用git add登记到index file里。
好了,对于git diff的用法就简单温习到这里吧。
- 在git提交环节,存在三大部分:working tree, index file, commit
- Difference between HEAD / Working Tree / Index in Git
- git pull/commit时,提示 “bad index file sha1 signature fatal: index file corrupt”错误
- git diff:对比working tree、stage、commit文件之间的不同
- git commit时出现fatal: Unable to create ‘××××.git/index.lock': File exists.
- nothing to commit, working tree clean
- git commit时出现的问题The file will have its original line endings in your working directory
- git commit 提交最新更改
- git commit 提交注释规范
- Git Commit Template 提交模板
- Git Commit Template 提交模板
- Git 提交模板 Commit Template
- git commit --amend 改写提交
- iOS git commit 提交操作
- GIT 删除指定COMMIT提交
- Git 学习 -4 Working Directory , Index
- error: Untracked working tree file ' ' would be overwritten by merge git checkut
- git 提交出现这个错误fatal: Unable to create 'project_path/.git/index.lock': File exists.
- MYSQL数据类型对应Java数据类型
- Android源码之Parcel
- C++中的const
- win7旗舰版 IIS的安装与设置
- LINUX系统备份工具
- 在git提交环节,存在三大部分:working tree, index file, commit
- RedHat 4 as 下安装Oracle11gR2,Cluster(ASM)和Database
- 自定义的activity设置为透明色
- Java Mail邮件SMTP协议返回信息 535 5.7.3 Authentication unsuccessful.
- 初学者比较容易犯的布局错误(手风琴布局)
- C#判断操作系统是32位还是64位的方法
- 使用JQUERY解决跨域访问
- spring 结合 redis 例子 (转载,以备后用)
- [操作系统实验] Todo - list