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

我尝试了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隐藏弹出之前没有阶段性的更改,那么下面两个命令应该可以工作。

git diff --name-only --cached | xargs git checkout --ours HEAD
git ls-tree stash@{0}^3 --name-only | xargs rm

第一种方法将从存储中反转任何合并,不管成功与否。第二个删除由隐藏引入的任何未跟踪的文件。

从man git stash:工作目录必须匹配索引。@DavidG指出,如果当前任何未分段修改的文件发生冲突,隐藏弹出将失败。因此,除了返回HEAD之外,我们不应该担心解除合并冲突。任何剩余的修改文件都与存储无关,并且是在存储弹出之前修改的

如果有阶段性的变化,我不清楚我们是否可以依赖相同的命令,你可能想尝试@Ben Jackson的技巧。建议表示赞赏。

下面是针对所有不同情况的测试设置https://gist.github.com/here/4f3af6dafdb4ca15e804

# Result:
# Merge succeeded in m (theirs)
# Conflict in b
# Unstaged in a
# Untracked in c and d

# Goal:
# Reverse changes to successful merge m
# Keep our version in merge conflict b
# Keep our unstaged a
# Keep our untracked d
# Delete stashed untracked c

如果DavidG是正确的,它没有弹出隐藏,因为合并冲突,那么你只需要清理你的工作目录。赶快提交你关心的一切。(如果没有完成,可以稍后重置或压缩提交。)然后,你所关心的一切安全,git重置其他一切,git stash弹出转储到你的工作目录。

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