在Git中取消隐藏弹出窗口 [英] Aborting a stash pop in Git

查看:109
本文介绍了在Git中取消隐藏弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试过 git merge --abort ,但git声称没有合并进行中。有没有一种简单的方法来中止流行而不破坏我最初在目录中的变化?

已经制定了混帐藏匿不适用。它比 git apply --reverse 要复杂得多,因为在 git stash apply 完成任何合并的情况下,您需要反向合并操作

反向合并要求将所有当前更改推入索引:


  • git add -u



然后将 git stash apply :



    c code> merge-recursive
  • git merge-recursive stash @ {0}: - $(git write-tree)stash @ {0} ^ 1



现在您只剩下非隐藏的更改。他们将在索引中。您可以使用 git reset 来取消您的更改。



鉴于您的原始 git stash apply 失败我认为反向也可能失败,因为它想撤消的一些事情没有完成。



这是一个示例显示工作副本(通过 git status )最终再次清理:

 在分支中继上
不需要提交(工作目录清理)
$ git stash apply
自动合并foo.c
#开启分支中继
#已更改但未更新:
#(使用git add< file> ...来更新将提交的内容)
#(使用git checkout - < ; file> ...放弃工作目录中的更改)

#modified:foo.c

没有更改添加到提交中(使用git add和/或git commit -a)
$ git add -u
$ git merge-recursive stash @ {0}: - $(git write-tree)stash @ {0} ^ 1
自动合并foo.c
$ git status
#在分支机箱上
没有提交(工作目录干净)


I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to keep. I don't just want to make the merge conflict disappear, but also to get my directory back to the state it was before the pop.

I tried git merge --abort, but git claimed no merge was in progress. Is there an easy way to abort a pop without destroying the changes I originally had in the directory?

解决方案

Ok, I think I have worked out "git stash unapply". It's more complex than git apply --reverse because you need reverse merging action in case there was any merging done by the git stash apply.

The reverse merge requires that all current changes be pushed into the index:

  • git add -u

Then invert the merge-recursive that was done by git stash apply:

  • git merge-recursive stash@{0}: -- $(git write-tree) stash@{0}^1

Now you will be left with just the non-stash changes. They will be in the index. You can use git reset to unstage your changes if you like.

Given that your original git stash apply failed I assume the reverse might also fail since some of the things it wants to undo did not get done.

Here's an example showing how the working copy (via git status) ends up clean again:

 $ 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中取消隐藏弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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