撤消git隐藏弹出导致合并冲突 [英] Undo git stash pop that results in merge conflict

查看:157
本文介绍了撤消git隐藏弹出导致合并冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始修改我的代码库,没有意识到我在一个旧的主题分支上。为了转移它们,我想存储它们,然后将它们应用到主分支之外的新分支。我使用> git stash pop 将正在进行的修改转移到这个新的分支上,忘记了在创建新的分支之前我没有将新的修改引入master。这导致了一堆合并冲突和我的更改丢失了一个干净的藏匿(因为我使用弹出)。

一旦我正确地重新创建新的分支,我怎么能我恢复了我的隐藏更改以正确应用它们?

解决方案

事实证明,Git足够聪明,如果它不能很好地应用,我可以通过以下步骤达到所需的状态:
$ b $ ol <

  • 取消合并冲突: git reset HEAD。

  • 保存冲突的合并(以防万一): git stash

  • 要返回到master: git checkout master

  • 要取得最新更改: git获取上游; git merge upstream / master

  • 更正我的新分支: git checkout new-branch; git rebase master

  • 要应用正确的装载更改(现在是堆栈中的第二个): git stash apply stash @ {1}


  • 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:

    1. To unstage the merge conflicts: git reset HEAD .
    2. To save the conflicted merge (just in case): git stash
    3. To return to master: git checkout master
    4. To pull latest changes: git fetch upstream; git merge upstream/master
    5. To correct my new branch: git checkout new-branch; git rebase master
    6. To apply the correct stashed changes (now 2nd on the stack): git stash apply stash@{1}

    这篇关于撤消git隐藏弹出导致合并冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆