撤消Intellij Smart Checkout [英] Undo Intellij Smart Checkout

查看:515
本文介绍了撤消Intellij Smart Checkout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Intellij具有理论上非常酷的功能,称为

Intellij has a feature that's very cool in theory, called Smart Checkout. This feature kicks in when you're changing branches and you have files in the current branch that you've modified but haven't committed.

它不是强制您提交,存储或搁置更改,而是为您存储更改,切换分支,然后在新分支中运行stash pop.

Instead of forcing you to commit, stash or shelve your changes, it stashes them for you, switches branches, then runs stash pop in the new branch.

我想这有时是您想要的,但是当切换到错误的分支时,我会执行此操作.

I guess this is what you'd want sometimes, but I ran this when switching to the wrong branch.

所以,现在我的master分支都充满了属于另一个分支的更改,一些文件报告了合并冲突,而我却感到各种各样的痛苦.

So, now my master branch is all full of changes that belong in another branch, some files are reporting merge conflicts, and I have all kinds of pain.

我想完成的是:

  1. 从master分支中干净地删除更改.
  2. 将它们移回我工作的分支机构.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

如果您在stash pop期间发生合并冲突,则至少可以使用部分答案.如我的问题所述,Smart Checkout功能使用stash来存储本地更改,然后在检出后将其应用于新分支.

Here's at least a partial answer that works if you had a merge conflict during the stash pop. As mentioned in my question, stash is used by the Smart Checkout feature to stash your local changes, and then to apply them to the new branch after it is checked out.

Intellij进行此操作的方法是在当前所在的分支中使用stash,然后在要切换到的分支中使用stash pop.

The way Intellij does this is by using stash in the branch you're presently in, and then using stash pop in the branch you're switching to.

将更改隐藏后,将它们放在顶部的一叠隐藏的更改中.然后,当stash pop运行时,这些更改将从堆栈中弹出并应用.

When the changes are stashed, they get put onto a stack of stashed changes, at the top. Then, when stash pop runs, those changes are popped off the stack and applied.

至少在大多数情况下,这就是发生的情况.但是,如果存在合并冲突,则Intellij会通知您,并且将保留藏匿处.您可以通过运行以下命令查看隐藏的堆栈:

At least, in most cases, that's what happens. If there's a merge conflict, however, Intellij informs you of such and the stash is kept. You can see the stack of stashes by running:

git stash list

如果您想要的存储区仍在列出中,那么您只需签出您原来所在的分支即可.重置它,然后执行stash apply,类似于stash pop,但不会从列表中删除存储.所以:

If the stash you want is still listed, what you can do is simply checkout the branch you were originally on. Reset it, then do stash apply, which is like stash pop, but doesn't remove the stash from the list. So:

git checkout $original-branch
git reset HARD
git stash apply

然后,如果一切顺利,则可以使用以下方式删除存储空间:

Then, if all is well, you can remove the stash with:

git stash drop

由于这个答案很粗糙,仅涵盖一种情况,因此我将其标记为社区Wiki.改进非常值得欢迎.

Since this answer is pretty rough and only covers one situation, I'm marking as a community wiki. Improvements very much welcome.

这篇关于撤消Intellij Smart Checkout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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