git stash 存储当前工作目录的已存储或未存储的更改或未跟踪的文件,然后将它们存储在存储堆栈中
当暂存完成后, 可将分支切换到其他分支
当分支切换回原开发分支时, 将当前工作目录恢复到最后一次提交。
参考
https://git-scm.com/docs/git-stash/zh_HANS-CN
https://www.freecodecamp.org/news/git-stash-commands/
- git 初始化
/Users/sean/IdeaProjects/gittest
~$ ls
about.md stash1.md
~$ git status
On branch about1
Your branch is up to date with 'origin/about1'.
nothing to commit, working tree clean
- git 修改
--about.md文件增加了一行内容 stash1
- git stash 操作
~$ git stash
Saved working directory and index state WIP on about1: 90f3f29 commit1
~$ git stash list
stash@{0}: WIP on about1: 90f3f29 commit1
- git checkout master / git checkout 回来
~$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
~$ git checkout about1
Switched to branch 'about1'
Your branch is up to date with 'origin/about1'.
~$ cat about.md
about
- git stash apply
~$ git stash list
stash@{0}: WIP on about1: 90f3f29 commit1
~$ git stash apply
On branch about1
Your branch is up to date with 'origin/about1'.
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: about.md
no changes added to commit (use "git add" and/or "git commit -a")
~$ cat about.md
about
stash1
- git stash drop
~$ git stash drop
Dropped refs/stash@{0} (0045f389d40855e16a841bd7fb154d4655f40820)
- git commit -a -m '提交'
~$ git commit -a -m 'stash1'
[about1 83ec7c5] stash1
1 file changed, 1 insertion(+)
~$ git push origin
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 10 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:appinn/gittest.git
90f3f29..83ec7c5 about1 -> about1