首页 > 解决方案 > 使用具有不同分支的 git stash

问题描述

我有两个分支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特定分支的工作中是体现)?

标签: gitgit-branch

解决方案


返回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}"

推荐阅读