我开了个藏宝箱,合并发生了冲突。与被列为重复的问题不同,我已经在我想保留的目录中有一些未提交的更改。我不只是想让合并冲突消失,还想让我的目录恢复到弹出窗口之前的状态。
我尝试了git合并-abort,但git声称没有合并正在进行中。是否有一种简单的方法来中止弹出,而不破坏我原来在目录中的更改?
我开了个藏宝箱,合并发生了冲突。与被列为重复的问题不同,我已经在我想保留的目录中有一些未提交的更改。我不只是想让合并冲突消失,还想让我的目录恢复到弹出窗口之前的状态。
我尝试了git合并-abort,但git声称没有合并正在进行中。是否有一种简单的方法来中止弹出,而不破坏我原来在目录中的更改?
当前回答
合并——只有当你合并其他分支代码并且它有冲突时才会中止。
git merge --abort
如果stash pop有冲突,你可以使用:
git reset --merge
其他回答
好吧,我想我已经解决了"git stash unapply"。它比git apply -reverse更复杂,因为你需要反向合并操作,以防git stash apply做了任何合并。
反向合并要求所有当前更改都被推入索引:
Git add -u
然后反转由git stash apply完成的合并递归:
——$(Git write-tree) stash@{0}^1
现在你将只剩下非隐藏的变化。它们会在索引中。如果你愿意,你可以使用git重置来取消你的更改。
鉴于你最初的git stash应用失败了,我假设反向也可能失败,因为它想要撤消的一些事情没有完成。
下面是一个例子,展示了工作副本(通过git状态)如何再次干净:
$ git status
# On branch trunk
nothing to commit (working directory clean)
$ git stash apply
Auto-merging foo.c
# On branch trunk
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo.c
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u
$ git merge-recursive stash@{0}: -- $(git write-tree) stash@{0}^1
Auto-merging foo.c
$ git status
# On branch trunk
nothing to commit (working directory clean)
我的用例:只是尝试弹出到错误的分支并得到冲突。我所需要的是撤消弹出,但保持它在收藏列表,以便我可以弹出它在正确的分支。我是这样做的:
git reset HEAD --hard
git checkout my_correct_branch
git stash pop
一件容易的事。
我可以在“脏”目录上重新生成干净的git stash pop,具有未提交的更改,但尚未生成合并冲突的pop。
如果在合并冲突中,你试图应用的stash没有消失,你可以尝试检查git show stash@{0}(可选与-ours或-their),并与git statis和git diff HEAD进行比较。您应该能够看到哪些更改来自应用存储。
I'm posting here hoping that others my find my answer helpful. I had a similar problem when I tried to do a stash pop on a different branch than the one I had stashed from. On my case I had no files that were uncommitted or in the index but still got into the merge conflicts case (same case as @pid). As others pointed out previously, the failed git stash pop did indeed retain my stash, then A quick git reset HEAD plus going back to my original branch and doing the stash from there did resolve my problem.
如果你不需要担心你所做的任何其他更改,你只想回到上次提交,那么你可以这样做:
git reset .
git checkout .
git clean -f