Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abort Git Merge in PhpStorm

Situation:

  1. Merged a branch
  2. Made a mistake while merging.
  3. I need to abort the merge and start over.

I previously used Tower for Mac to manage my git repository. I'm trying to make the switch to using PhpStorm to manage my git repo but it seems to be missing some features.

In Tower there is an "Abort" button which allows me to easily undo my messed up merge and start over. Simply click the "Abort" button and it reverts everything perfectly like you never even started the merge.

Tower for Mac Abort Merge Button

Tower for Mac Abort Merge Button

Question:

Is there a simple way to abort/undo a merge in PhpStorm?

like image 502
zechdc Avatar asked Jun 03 '16 15:06

zechdc


People also ask

How do I abort a git merge?

How do I cancel a git merge? Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

How do you abort a failed merge?

On the command line, a simple "git merge --abort" will do this for you. In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.

How do you cancel commit before push Phpstorm?

Locate the commit you want to revert in the Log tab of the Git tool window Alt+9 , right-click it and select Revert Commit from the context menu. This option is also available from the context menu of a commit in the file History view. The Commit Changes dialog will open with an automatically generated commit message.

What does aborting a merge do?

So the “git merge –abort” operation essentially terminates the merger that you have just carried out and separated the two versions of your file, i.e., the current version and the older version.


2 Answers

GUI

In new versions of phpStorm use the function "Git" -> "Abort Merge". In old versions use "VCS" -> "Git" -> "Reset Head" and choose the "Hard" option.

You will lose all changes, so be careful.

Screenshot

CLI

git merge --abort

like image 127
guybrush Avatar answered Oct 25 '22 17:10

guybrush


If you only want to undo the changes to a single file somefile then you can try the following:

git checkout -- path/to/somefile

In case you want to undo the entire merge operation, then git reset will come in handy:

git reset --hard HEAD

Both of these operations are resetting the state to the HEAD of the branch, which is the last commit made before you attemtped a merge.

like image 38
Tim Biegeleisen Avatar answered Oct 25 '22 19:10

Tim Biegeleisen