4、打开test.txt,向其中加入些内容,保存。
Hello world
其实就多了world这个字符串。再次用git status查看文件状态。
除了之前的“Changes to be committed”状态,还多了“Changes not staged for commit”状态,表明文件已经被修改,但修改还没有放入暂存区域,也就是没生成快照。如果此时进行commit操作,只会提交"Hello",忽略 “world”。
根据提示,如果想把最新的修改“Hello world”提交到仓库,需要再次使用命令git add test.txt;如果想撤销修改,即只想提交“Hello”,可以使用git checkout -- test.txt,再次git status,则可以看到状态又改变了。
总结:所以,在文件未进行commit操作之前,存在三种状态:Untracked files, Changes not staged for commit, Changes to be committed. 每种状态可以随意转换。
--------------------------------------------------------------------------------------------------------
题外话
--------------------------------------------------------------------------------------------------------
在git的后续版本中,添加了git stage作为git add的一个同义词,这样在语义上更符合上面的Changes not staged for commit。为什么要增加stage呢?
1、分批提交,降低commit的粒度。
2、文件快照,便于回退。
如果一次提交过多文件,对后续的回滚或跟进无疑非常不利,对问题的定位也不便,体验过估计清楚的。比如你做了两个功能A和B,对应的文件修改分别是a1.java, a2.java; b1.java, b2.java,提交时就可以这样:
git stage a1.java a2.java git commit -m "功能A"
git stage b1.java b2.java git commit -m "功能B"
同时,每次修改后stage,任何时刻,都可以回到上一次staged的状态:
git checkout -- test.txt
如果想从stage中删除,则使用reset
git reset test.txt
这个命令就是git stage test.txt的反操作。
2015职称计算机考试书PowerPoint2007中 .. 定价:¥45 优惠价:¥42 更多书籍 | |
2015年全国职称计算机考试教材(2007模 .. 定价:¥225 优惠价:¥213 更多书籍 |