如果改动了working area和staging area的文件,需要保存起来,然后忽略这些改动,回到最后一次提交的状态。可以使用git stash.
假定项目中有一个文件t,先用git rm t 从删除之,这时候working area中该文件消失了。
然后执行git stash命令,再看working area中,该文件又回来了。
这时候调用git stash list命令,看到:
git stash list
stash@{0}: WIP on master: 1c47165 change package name
这次的改动没有彻底丢掉,而是被保存到stash list中。可以认为是搁置争议,保留个人意见,虽然服从了大局,但是个人的意见还是存在了一个stash list的地方,以后随时可以拿出来。
拿出来的话,用git stash pop,
Removing t
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: t
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# deploy.tar.bz2
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (8e32484d1da7ab8e47986e1aff39a5711087dcc2)
结果可以看到,又回到我用git rm删除t文件的状态。