问题
- develop 分支上有 add 但还没有 commit 的文件。
- 切换到 other 分支后,这些文件在 other 分支下也能被看到。
- 为什么,怎么解决
小知识
如何隐藏当前暂存区内容
# 初始化一个 git 库
$ git init
$ ll ./ > aa.txt
$ git add .
$ git commit -m "committed aa..txt"
# 隐藏当前分支的工作现场(必须添加到暂存区)
$ ll ../ > bb.txt
$ git add .
$ git stash
# 可以多次隐藏
$ ll ../../ > cc.txt
$ git add .
$ git stash
# 查看隐藏的工作现场,最近保存的在列表的最上面
$ git stash list
stash@{0}: WIP on develop: 96ac618 committed aa.txt
stash@{1}: WIP on develop: 96ac618 committed aa.txt
# 恢复现场,两种方法
## 第一种, git stash apply 恢复, 然后要手工删除 stash 内容, git stash drop删除
### 恢复最近保存的现场
$ git stash apply
### 恢复指定的现场
$ git stash apply stash@{1}
$ git stash apply stash@{0}
### 清空隐藏的现场
$ git stash drop
## 第二种, git stash pop 恢复,自动会清除 stash 内容
### 恢复最近保存的现场
$ git stash pop
### 恢复指定的现场
$ git stash pop stash@{0}
解决过程
# 切回 develop 分支
$ git checkout develop
# 删除 other 分支
$ git branch -d other
# 把文件藏起来,让工作区看起来干净
$ git stash
# 再创建 other 分支
$ git checkout -b other
# 验证,工作区很干净
$ git status
On branch other
nothing to commit, working tree clean
# 在 other 分支上干完活后,合入 develop 分支,删除 other 分支,
## 再恢复之前隐藏的文件
$ git stash apply stash@{0}
## 删除隐藏的备份
git stash drop