git的文件状态以及git diff结果分析 (staged已暂存的,unstaged取消暂存的)
2015-04-20 14:03
405 查看
git file
git库所在的文件夹(即.git所在的文件夹)中的文件大抵就是这四种状态。
untracked:未跟踪,此文件在文件夹中,但并没有加入git库,不参与版本控制。 通过”git add”,”git commit”可将它置入跟踪库。
unmodify:文件已经库中,未修改,即版本库中的文件快照内容与文件夹中完全一致。这种类型的文件有两个去处,如果它被修改,而成为modified。如果使用”git rm”移出版本库,则成为untracked文件。
modified:文件已修改,仅仅是修改,并没有进行其它操作。这个文件也有两个去处,通过”git add”可进入暂存(staged)状态,使用”git checkout”则丢弃修改,返因到unmodify状态。这个checkout很好理解,就是取出库中文件,覆盖当前文件吧。
staged:暂存状态。执得”git commit”则将修改同步到库中,这时库中的文件与本地文件又一致了,于是文件是unmodify状态。执行”git reset HEAD filenam”取消暂存,文件状态变为modified。
git diff
可以用来比较:
1.staging area和working area的文件 (无其他参数时)
[plain] view plaincopyprint?
git diff
2.master分支和working area的文件 (用master参数)
[plain] view plaincopyprint?
git diff master
3.HEAD指向的内容和working area的文件
[plain] view plaincopyprint?
git diff HEAD
4.用远程master分支比较当前工作区
[plain] view plaincopyprint?
git diff refs/remotes/origin/master
5.经常还要用到master分支的某个文件的历史版本和working area的该文件的比较
[plain] view plaincopyprint?
git diff 0c5ee16a6a4c849d0ae0448caa8ff174399c7c3c ./socket_helper.cpp
上面的命令中, diff后面的参数指的是commit id, ./socket_helper.cpp是要比较的文件路径。
diff的命令输出格式注意:
[plain] view plaincopyprint?
---代表源文件
+++代表目标文件
通常working area的文件都是被当作目标文件来看待。
-开头的行,是只出现在源文件中的行
+开头的行,是只出现在目标文件中的行
空格开头的行,是源文件和目标文件中都出现的行
差异按照差异小结进行组织,每个差异小结的第一行都是定位语句,由@@开头,@@结尾。
[plain] view plaincopyprint?
chenshu@chenshu-yangzhou-home:~/kaimei/data_service/src$ git diff 0c5ee16a6a4c849d0ae0448caa8ff174399c7c3c ./socket_helper.cpp
diff --git a/data_service/src/socket_helper.cpp b/data_service/src/socket_helper.cpp
index d606452..047e213 100755
--- a/data_service/src/socket_helper.cpp
+++ b/data_service/src/socket_helper.cpp
@@ -4,6 +4,7 @@
#include "data/login_response.h"
#include "data/heartbeat_response.h"
#include "helper/parser.h"
+#include "helper/time_measure.h"
#include <booster/log.h>
#include "exception/socket_error.h"
#include "exception/data_error.h"
上面的diff结果表明
1.某个提交记录0c5ee代表的socket_helper.cpp文件是源文件,当前working area的socket_helper文件是目标文件。
2.在源文件第4行开始的6行和目标文件第4行开始的7行构成一个差异小结
3.这个差异小结中,目标文件添加了一行#include "helper/time_measure.h"
4.其他空格开头的行表明没有差异。
相关文章推荐
- Git 暂存修改文件 取消暂存
- git - 查看已暂存和未暂存的更新以及文件修改之后暂存区、上次提交过的不同
- git diff 输出结果分析
- Git使用手册/Git教程:找回删除的版本代码/git reflog与git log的区别/取消暂存区文件的暂存
- Git diff结果显示分析
- git - 移除文件以及取消对文件的跟踪
- .gitignore文件无效的原因以及解决方式
- git 文件状态的生命周期
- 错误蓝屏死机重启产生的.dmp文件如何打开以及如何分析蓝屏的原因
- ADS.12的工程建立与配置以及其中一些文件的分析
- 批量添加文件到git仓库暂存区
- Android中View(视图)绘制不同状态背景图片原理深入分析以及StateListDrawable使用详解
- git show查看本地文件的修改部分,git diff 如何比较文件,git grep 搜索
- 【个人机房重构】—— 抽象工厂+反射+配置文件详解以及错误分析
- jmeter对聚合报告,查看观察树,以及图形结果的分析
- python读取 .txt 文本内容以及将程序执行结果写入txt文件
- 如何高效撤销Git管理的文件在各种状态下的更改 ?
- git快速入门(四)工作区,暂存区以及master分支
- Git 取消跟踪已版本控制的文件(亲测可行)
- Git中三种文件状态及其转换(转)