Returning failed merge branches

I combined my branch into a workshop and pushed, thinking that everything was in order. It turns out that the code has problems, and I need a way to undo either the merge commit, or the whole branch, depending on which is more suitable, so that others can easily continue working as if my merge never happened.

Then I intend to fix my branch and merge it again. Reading man git-revert suggests that I can re-merge if I use -m to return the entire branch.

+6
source share
1 answer

Just reset HEAD for the previous commit:

 git reset --hard HEAD^ 

You do not state in your question if you pushed your erroneous merger or not, so you need to click with -force if that is the case (since you rewrote the story on the main branch).

Please note that rewriting history can cause problems for other developers if they based their work on erroneous commit. In this case, you might think:

 git revert HEAD 

However, this will create a new commit, which makes the opposite commit that HEAD is pointing to right now, and ruin the repository. Resetting is better in this sense, since you are getting rid of two commits, one of them is faulty and one to compensate for the malfunction.

+6
source

Source: https://habr.com/ru/post/910588/


All Articles