git stash
用于暫存工作區未提交的內容,便于在同時開發多個分支需要切換時保存當前分支進度。
-
list
語法git stash list [<options>]
,與git log
功能類似,列出儲藏列表,options 參數可以參考git log
的參數 -
show
語法git stash show [<options>] [<stash>]
,和git show
功能類似 -
save
語法git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all] [<message>]
,- 將本地更改保存到新的儲藏隊列,
[-p|--patch]
以patch
模式提交,允許選擇需要保存的塊,具體參考git add
的--patch
模式[-k|--[no-]keep-index]
[不]保留 index 序號[-q|--quiet]
靜默執行,即不顯示結果[-u|--include-untracked]
儲藏時包括未跟蹤的文件[-a|--all]
儲藏所有文件,包括忽略的文件- 建議使用
push
代替save
-
push
語法git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all] [-m|--message <message>] [--] [<pathspec>...]]
- 將本地修改保存到新的儲藏隊列,用法與save基本一致,多了
[--] [<pathspec>...]
可選參數 [--] [<pathspec>...]
使用路徑匹配,只有路徑匹配下的文件會被儲藏,通常用于儲藏部分文件push
選項可以被省略,以便快速保存,省略push
時,不能使用參數
- 將本地修改保存到新的儲藏隊列,用法與save基本一致,多了
-
pop | apply
語法git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
,取出指定的隊列,默認取出最新的隊列,pop
與apply
的區別在于,pop
在取出隊列后會刪除stash中的隊列,apply
則不會刪除 -
drop
語法git stash drop [-q|--quiet] [<stash>]
,刪除某個儲藏隊列,默認刪除最新的儲藏隊列 -
clear
語法git stash clear
,刪除所有儲藏 -
branch
語法git stash branch <branchname> [<stash>]
,使用某個儲藏隊列建立分支,同時刪除該隊列
[<stash>]
指stash隊列的名稱,形式為stash@{id}