使用 git stash 和不同的分支

Working with git stash with different branches

我有两个分支 feature/Afeature/B。我已经修改了 feature/A 的文件并应用 git stash 命令保存我的工作,并应用 git checkout feature/B 切换到其他分支。现在 feature/B 我修改了文件并应用 git stash 将工作保存在 feature/B

现在,如果我想再次反映我的更改,我必须应用 git stash pop,但我的问题是当我应用 git stash pop 或工作被保存时,两个分支的保存工作会立即反映出来根据分支(即在 feature/A 中,特定分支的工作仅反映,在 feature/B 中,特定分支的工作被反映)?

您可以在返回 feature/A 分支后按索引弹出或应用相关存储。考虑这个工作流程:

# work on feature/A
git stash

# work on feature/B
git checkout feature/B
git stash

# now return to feature/A and apply the first stash
git checkout feature/A
git stash apply "stash@{0}"

# switch to feature/B and apply the correct stash there
git checkout feature/B
git stash apply "stash@{1}"