我开了个藏宝箱,合并发生了冲突。与被列为重复的问题不同,我已经在我想保留的目录中有一些未提交的更改。我不只是想让合并冲突消失,还想让我的目录恢复到弹出窗口之前的状态。

我尝试了git合并-abort,但git声称没有合并正在进行中。是否有一种简单的方法来中止弹出,而不破坏我原来在目录中的更改?


当前回答

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 stash pop,具有未提交的更改,但尚未生成合并冲突的pop。

如果在合并冲突中,你试图应用的stash没有消失,你可以尝试检查git show stash@{0}(可选与-ours或-their),并与git statis和git diff HEAD进行比较。您应该能够看到哪些更改来自应用存储。

好吧,我想我已经设法找到了一个工作流程,可以让你回到你需要的地方(就像你没有做流行一样)。

事先做个备份!!我不知道这是否适用于你,所以复制你的整个回购以防它不起作用。

1)修复合并问题,并通过选择所有来自补丁的更改来修复所有冲突(在tortoisemerge中,这显示为一个)。REMOETE(他们的))。

git mergetool

2)提交这些更改(它们已经通过mergetool命令添加)。给它一个“合并”的提交消息或其他你记得的东西。

git commit -m "merge"

3)现在你仍然会有你最初开始的本地未分阶段的变化,从补丁中重新提交(我们可以稍后摆脱这个)。现在提交未分阶段的更改

git add .
git add -u .
git commit -m "local changes"

4)反转补丁。这可以通过以下命令来完成:

git stash show -p | git apply -R

5)提交以下更改:

git commit -a -m "reversed patch"

6)取消patch/unpatch提交

git rebase -i HEAD^^^

从中删除带有“merge”和“reversed patch”的两行。

7)找回你的unstancing changes,并撤销“local changes”的提交

git reset HEAD^

我已经运行了一个简单的例子,它让你回到你想要的地方-直接在隐藏之前被弹出,与你的本地变化和隐藏仍然可用的弹出。

编辑:从弹出部分的git帮助隐藏文档:

应用状态可能会因冲突而失败;在这种情况下,它不会从收藏列表中删除。你需要手动解决冲突,然后手动调用git stash drop。

如果使用了——index选项,则不仅尝试恢复工作树的更改,还尝试恢复索引的更改。但是,当您有冲突时(冲突存储在索引中,因此您不能再像最初那样应用更改),这可能会失败。

试着硬拷贝你所有的repo到一个新目录(这样你就有了一个副本),然后运行:

Git stash显示和保存输出的地方,如果你关心它。

然后:git stash下降下降冲突的stash 然后:git重置头

这应该会使您的回购处于之前的状态(希望,我仍然无法重现您的问题)

===

我试图重现你的问题,但我得到的所有当使用git stash流行是:

error: Your local changes to the following files would be overwritten by merge:
...
Please, commit your changes or stash them before you can merge.
Aborting

在一个干净的目录下:

git init
echo hello world > a
git add a & git commit -m "a"
echo hallo welt >> a
echo hello world > b
git add b & git commit -m "b"
echo hallo welt >> b
git stash
echo hola mundo >> a
git stash pop

我没有看到git试图合并我的更改,它只是失败了。你有什么我们可以帮助你的重现步骤吗?

如果你不需要担心你所做的任何其他更改,你只想回到上次提交,那么你可以这样做:

git reset .
git checkout .
git clean -f

合并——只有当你合并其他分支代码并且它有冲突时才会中止。

git merge --abort

如果stash pop有冲突,你可以使用:

git reset --merge