git stash:储藏working directory和index的当前状态(不包括untracked文件)git stash apply:仅应用working directory的修改,不应用index的修改git stash list:stash列表git stash drop:删除stash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
$ gst -sb ## master M a.txt M b.txt $ git stash list # Stdout print nothing $ git stash # save working directory and index state Saved working directory and index state WIP on master: 2e5960b add a.txt b.txt HEAD is now at 2e5960b add a.txt b.txt $ gst On branch master nothing to commit, working directory clean $ git checkout -b dev $ git stash list [email protected] {0}: WIP on master: 2e5960b add a.txt b.txt$ git stash apply # default apply [email protected] {0} $ gst -sb # only apply working directory ## dev M a.txt M b.txt $ git stash drop [email protected] {0} Dropped [email protected] {0} (8ec72e0160fd187bcc90ddcc7066b9b6c22f350c) $ git stash list # Stdout print nothing
git stash apply --index
git stash apply --index:应用working directory和index的修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ gst -sb ## dev M a.txt M b.txt $ git stash Saved working directory and index state WIP on dev: 2e5960b add a.txt b.txt HEAD is now at 2e5960b add a.txt b.txt $ gst On branch dev nothing to commit, working directory clean $ git stash apply --index # apply working directory and index $ gst -sb ## dev M a.txt M b.txt
git stash --keep-index
git stash --keep-index:仅储藏working directory的修改,不储藏index的修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ gst -sb ## dev M a.txt M b.txt $ git stash --keep-index Saved working directory and index state WIP on dev: 2e5960b add a.txt b.txt HEAD is now at 2e5960b add a.txt b.txt $ gst -sb ## dev M a.txt $ git stash apply $ gst -sb ## dev M a.txt M b.txt
git stash -u
git stash -u:储藏untracked文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
$ gst -sb ## dev M a.txt M b.txt ?? c.txt $ git stash Saved working directory and index state WIP on dev: 2e5960b add a.txt b.txt HEAD is now at 2e5960b add a.txt b.txt $ gst -sb ## dev ?? c.txt $ git stash apply $ gst -sb ## dev M a.txt M b.txt ?? c.txt $ git stash -u Saved working directory and index state WIP on dev: 2e5960b add a.txt b.txt HEAD is now at 2e5960b add a.txt b.txt $ gst On branch dev nothing to commit, working directory clean
近期评论