git stashgit stash save 以储藏工作目录中的所有改动

$ git stash
Saved working directory and index state \\
  "WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")

$ git status # 就像提交过一样, 目录很干净
# On branch master
nothing to commit, working directory clean

# 查看储藏区储藏了多少次
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log

# 恢复储藏的工作目录状态
$ git stash apply
# 恢复工作目录状态, 且尝试恢复原来的暂存状态
$ git stash apply --index

# 删除某个储藏
$ git stash drop stash@{0}

# 把未暂存的放出储藏区, 然后提交已暂存的
$ git stash --keep-index
	# commit...

# 只储藏为跟踪的文件
$ git stash -u
	# -u --include-untracked

# 交互式决定是否储藏
$ git stash --patch

# 把储藏的内容恢复到一个分支里
$ git stash branch testchanges

清理工作目录

$ git clean # 清理工作目录所作的改动
$ git stash --all # 清理东西, 但是放在储藏区, 这是更安全的选项, 有后悔药可以吃

# 移除工作目录中所有未追踪的文件以及空的子目录
$ git clean -f -d
	# -f 强制(不用确认直接删)
$ git clean -d -n # 这真的是演习, 展示会有哪些清理动作

# .gitignore 文件中忽略的文件也一起删, 用-x 选项
$ git clean -n -d -x
	# -n 演习

# 以交互式模式运行clean 命令
$ git clean -x -i