3
I did an unnecessary merge with a branch, now I have several elements in staged and not merged because of conflicts. What’s the best way to reverse this merge and leave the branch in the last commit before this unwanted action?
3
I did an unnecessary merge with a branch, now I have several elements in staged and not merged because of conflicts. What’s the best way to reverse this merge and leave the branch in the last commit before this unwanted action?
3
Assuming the merge didn’t generate any commit (as there are conflicts). At the root of your repository, type
git reset .
This will remove all the changes that are staged, putting them back on the list of modified.
Then reverse all modifications:
git reset HEAD --hard
This will reverse all modifications to the modified files. Note that if you had any other modification, it will also be lost.
If the merge added new files to the repository, then you can "clean them" through the git clean
. Again from the repository root:
git clean -xdf
As always, be careful when using the git clean
since it can delete files that you would like to have. You can use the option n
in turn of f
to list the files that will be deleted.
The elements that were in modfy are as not monitored, what to do with these?
I edited the answer to cover this scenario.
Thank you very much!!! Solved my problem even! I didn’t worry about the deleted files as I am linked to a remote branch, so I pulled and brought everything back. Thank you very much friend!
-1
A merge can be canceled with
git merge --abort
According to GIT Book Pro https://git-scm.com/book/pt-pt/v2/Ferramentas-do-Git-Advanced-Merging
Browser other questions tagged git
You are not signed in. Login or sign up in order to post.
Well, talking to colleagues came to the conclusion that, the procedure is normal, turn the stageds with git reset HEAD <filename> and when all are in Modify, just give a checkout . " if it’s at the root" your branch will be at the last commit before the unwanted action.
– Rafael Caetano da Silva