当我们的git 本地仓库有多个分支进行开发时会遇到,当前分支工作目录的修改不想提交,但是又需要切换到另一分支的情况,我们就可以使用
git stash 储藏起我们的改动,然后放心的切换到其他分支
git stash ---- 储藏工作目录的改动
$ git stash - - help
git stash list [<options>]
git stash show [<stash>]
git stash drop [-q|--quiet] [<stash>]
git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
git stash branch <branchname> [<stash>]
git stash [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
git stash clear
git stash create
① git stash list --- 查看当前git仓库中 储藏列表
$git stash list
stash@{0}: WIP on master: a5f90bd add aa
stash@{1}: WIP on master: a5f90bd add aa
最近一次的stash 为数字最小的一个为 stash@{0}
②git stash show -- 查看stash列表里的stash
$git stash show stash@{0}
aa | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
$git stash show -p stash@{0}
diff --git a/aa b/aa
index e69de29..66223f4 100644
--- a/aa
+++ b/aa
@@ -0,0 +1 @@
+test git stash
-p 参数让列出的结果以diff patch的形式列出,自己储藏的改动显而易见。
③ git stash --- 将工作区的改动添加到新的stash中,同时使用git reset --hard 将工作去进行恢复
$git stash
Saved working directory and index state WIP on master: a5f90bd add aa
HEAD is now at a5f90bd add aa
$git stash save "stash aa file test git stash save " -- save 与注释可以忽略不写
Saved working directory and index state On master: stash aa file test git stash save
HEAD is now at a5f90bd add aa
$ git stash list
stash@{0}: On master: stash aa file test git stash save
stash@{1}: WIP on master: a5f90bd add aa
stash@{2}: WIP on master: a5f90bd add aa
$ git stash save --patch --- 进行交互式的储藏默认包含 --keep-index参数
$ git stash save --keep-index --- 储藏除暂存区以外的工作目录的改动
④ git stash pop --- 将储藏弹出,并在储藏列表中弹出
git stash pop --index ,不仅会恢复你工作目录的修改,而且会恢复暂存区的修改。就是各就各位,不然会全部认为是你工作目录的修改。
⑤ git stash apply --- 将储藏弹出但不删除
⑥ git stash clear --- 清除储藏列表
⑦ git stash branchname 创建一个新的分支来应用选定的储藏
至于 git stash create 还没有弄明白