08.stash-保存当前更改
1 什么是git stash?
  git stash用于保存当前的工作空间已经修改的文件到另一个地方去,从而清空当前的工作空间的修改。这样的事情通常发在如果代码写到一半时,要去做另外的事,比如到别的开发分支,或者需要写demo又不想demo污染正规的代码,不得临时保存写到一半的代码,腾出空间来写demo之类需求,而把当前写到一半的代码又不到一个提交粒度的代码先放到一边的场景等。
2 示例
$ git init                  # 初始化
$ touch index.log           # 新建立空文件
$ git add -A                
$ git commit -m 'init'      #  首页个提交
  commit 4fe2cdc29b614c34566db0a88f1888bb5dfbd613
  Author: wuchuheng <root@wuchuheng.com>
  Date:   Fri Apr 17 00:43:30 2020 +0800
$ echo 'crazy coding ...' > builcoding.log 
$ cat  builcoding.log
  crazy coding ...
$ git stash save 'save for master code' # 保存写到一半的代码
$ git stash list 
 stash@{0}: WIP on master: 4fe2cdc init # 保存的记录列表
$ git checkout -b demo # 到demo分支写demo
$ echo 'the code for demo' > builcoding.log
$ cat  builcoding.log
  the code for demo
$ git stash save 'code from demo'
$ git checkout master
$ git stash list 
 stash@{0}: WIP on master: save for master code
 stash@{1}: On demo: save for demo
$ git stash pop stash@{0}  # 现在又回到原来工作的分支上并原来的代码还原出来
$ cat  builcoding.log
 the code for demo
3 相关的命令
- git stash clear:删除所有保存列表
- git stash apply [options] : 使用一记录但是不删除