$ git stash save 'untracked' -u Saved working directory and index state On main: untracked
git stash -a
-a参数会暂存当前目录下所有修改,包括gitignore所忽略的文件,或者–all
1 2 3 4 5
$ git stash save 'a存储' -a warning: in the working copy of '.husky/_/applypatch-msg', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of '.husky/_/commit-msg', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of '.husky/_/h', LF will be replaced by CRLF the next time Git touches it ...
git stash list
查看已暂存记录
1 2 3
$ git stash list stash@{0}: WIP on main: f73bb62 Merge pull request #181 from Knogobert/main stash@{1}: On main: untracked
git stash apply
默认恢复最新暂存记录,但是不会删除暂存记录,添加stash@{1}表示恢复指定暂存记录
1 2 3 4 5 6 7 8
$ git stash apply On branch main Your branch is behind 'origin/main' by 14 commits, and can be fast-forwarded. (use "git pull" to update your local branch)
Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: components/content/inspira/ui/particle-image/new.vue
git stash pop
恢复最新暂存记录,同时会将缓存堆栈中的第一个stash删除,建议先apply再drop
1 2 3 4 5 6 7 8
$ git stash apply On branch main Your branch is behind 'origin/main' by 14 commits, and can be fast-forwarded. (use "git pull" to update your local branch)
Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: components/content/inspira/ui/particle-image/new.vue
git stash drop
移除最新暂存记录,添加stash@{1}表示移除指定暂存记录
1 2
$ git stash drop Dropped refs/stash@{0} (aa1e5cac7f59e2007bc1cdd04ba9324c23e6629a)
git stash clear
移除所有暂存记录
1
$ git stash clear
git stash branch
从最新暂存记录创建分支,如果成功,将会同时移除暂存记录,添加stash@{1}表示指定暂存记录
1 2 3 4 5 6 7 8 9 10
$ git stash branch feature_C stash@{1} Switched to a new branch 'feature_C' On branch feature_C Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: components/content/inspira/ui/particle-image/ParticleImage.vue
no changes added to commit (use "git add" and/or "git commit -a") Dropped stash@{1} (2603b7bb4d4c604f680c434325e24d5fe5677742)