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

我尝试了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.

其他回答

尝试使用if跟踪文件。

git rm <path to file>
git reset  <path to file>
git checkout <path to file>

使用git reflog列出在git历史中所做的所有更改。复制一个动作id,输入git reset ACTION_ID

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

git merge --abort

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

git reset --merge

一些想法:

使用git mergetool将合并文件拆分为原始部分和新部分。希望其中一个是包含你非隐藏更改的文件。 反向应用隐藏的diff来撤销这些更改。您可能必须手动分离合并冲突的文件(希望上面的技巧可以奏效)。

这两个我都没有测试过,所以我不确定它们是否能工作。

好吧,我想我已经解决了"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)