5.5 搁置问题,暂存状态

查看一下当前工作区的状态:


$git status

On branch master

Changes to be committed:

(use "git reset HEAD<file>…" to unstage)

#

new file:a/b/c/hello.txt

modified:welcome.txt

#

Changes not staged for commit:

(use "git add<file>…"to update what will be committed)

(use "git checkout—<file>…"to discard changes in working directory)

#

modified:a/b/c/hello.txt

#


在状态输出中,Git体贴地告诉了用户如何将加入暂存区的文件从暂存区撤出以便让暂存区和HEAD一致(这样提交就不会发生)。还告诉用户,对于暂存区更新后在工作区所做的再一次修改有两个选择:或者再次添加到暂存区,或者取消工作区新做出的改动。但是现在理解涉及的命令还有些难度,一个是git reset,一个是git checkout。需要先理解什么是HEAD,什么是master分支,以及Git对象存储的实现机制等问题,这样才可以更好地操作暂存区。

为此,我做出一个非常艰难的决定:就是保存当前的工作进度,在研究了HEAD和master分支的机制之后,继续对暂存区的探索。命令git stash就是用于保存当前工作进度的。


$git stash

Saved working directory and index state WIP on master:e695606 which version

checked in?

HEAD is now at e695606 which version checked in?


运行完git stash之后,再查看工作区状态,会看见工作区尚未提交的改动(包括暂存区的改动)全都不见了。


$git status

On branch master

nothing to commit(working directory clean)


"I'll be back。"(我会再回来的。)——施瓦辛格,《终结者》,1984。