问题描述
我开始修改我的代码库,没有意识到我在一个旧的主题分支上。为了转移它们,我想存储它们,然后将它们应用到主分支之外的新分支。我使用> git stash pop 将正在进行的修改转移到这个新的分支上,忘记了在创建新的分支之前我没有将新的修改引入master。这导致了一堆合并冲突和我的更改丢失了一个干净的藏匿(因为我使用弹出)。
一旦我正确地重新创建新的分支,我怎么能我恢复了我的隐藏更改以正确应用它们?
事实证明,Git足够聪明,如果它不能很好地应用,我可以通过以下步骤达到所需的状态:
$ b $ ol <
I began making changes to my codebase, not realizing I was on an old topic branch. To transfer them, I wanted to stash them and then apply them to a new branch off of master. I used git stash pop to transfer work-in-progress changes to this new branch, forgetting that I hadn't pulled new changes into master before creating the new branch. This resulted in a bunch of merge conflicts and loss of a clean stash of my changes (since I used pop).
Once I recreate the new branch correctly, how I can I recover my stashed changes to apply them properly?
As it turns out, Git is smart enough not to drop a stash if it doesn't apply cleanly. I was able to get to the desired state with the following steps:
- To unstage the merge conflicts: git reset HEAD .
- To save the conflicted merge (just in case): git stash
- To return to master: git checkout master
- To pull latest changes: git fetch upstream; git merge upstream/master
- To correct my new branch: git checkout new-branch; git rebase master
- To apply the correct stashed changes (now 2nd on the stack): git stash apply stash@{1}
这篇关于撤消git隐藏弹出导致合并冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!