Cancel Intellij Smart Checkout

Intellij has a feature that is very cool in theory called Smart Checkout . This function works when you change branches, and you have files in the current branch that you changed but did not.

Instead of forcing you to make, store, or delay your changes, it forces them for you, switches branches, and then runs stash pop in a new branch.

I guess this is what you would like sometimes, but I ran this, switching to the wrong branch.

So, now my master branch is filled with changes belonging to another branch, some files report merge conflicts, and I have all kinds of pain.

I want to do the following:

  • Cleanly remove the changes from the main branch.
  • Move them back to the branch where I worked.

Is there any way to do this?

+5
source share
1 answer

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

The way Intellij does this is used by stash in the branch you are currently in, and then using stash pop in the branch you are switching to.

When changes are hidden, they are pushed onto the stack of folded changes at the top. Then, when stash pop starts, these changes exit the stack and apply.

At least in most cases, what happens. However, if there is a merge conflict, Intellij informs you of this, and the cache remains. You can see the delay stack by running:

 git stash list 

If you want to keep everything you want, just check which branch was originally included. Reset it, then do stash apply , which is similar to stash pop , but will not remove stash from the list. So:

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

Then, if all goes well, you can remove the tab using:

 git stash drop 

Since this answer is rather crude and covers only one situation, I mark it as a community wiki. Improvements are very welcome.

+5
source

All Articles