What is the best way to undo a merge with elements in staged and modfy with conflicts?

2

I made an unnecessary merge with a branch, now I have several elements in staged and not mixed due to the existence of conflicts. What is the best way to reverse this merge and leave the branch on the last commit before this unwanted action?

    
asked by anonymous 04.02.2016 / 19:24

1 answer

2

Assuming merge did not commit (since there are conflicts). In the root of your repository, type

git reset .

This will remove all changes that are staged , putting them back in the modified list.

Then reverse any changes:

git reset HEAD --hard

This will revert all modifications to the modified files. Note that if you had any other modification, it will also be lost.

If the merge has added new files to the repository, then you can "clean" them with git clean . Again from the root of the repository:

git clean -xdf

As always, be careful when using git clean since it can delete files that you would like to have. You can use the n option in f to list the files that will be deleted.

    
04.02.2016 / 19:54