Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - how to revert a merge

I am using Intellij and Git.

I mistakenly merged our development branch into our autoapproval_hierarchy_ui branch and pushed it to the remote repo. Now I would like to revert that merge.

Please can someone advise how I can do so?

I would like to basically have it exactly like it was before I did the merge, i.e. at 2020/04/06 at 10:35 (ass you can see in the picture below).

enter image description here

This means it will no longer have the changes from the development branch in the autoapproval_hierarchy_ui branch on the remote repo.

I have tried to 'Reset Current Branch to Here...',

enter image description here

and this sets my local workspace in the desired state,

enter image description here

but I cannot seem to push that state to the remote repo.

If I do a:

Git -> Compare with Branch... -> autoapproval_hierarchy_ui

There are all the merge differences.

UPDATE

Based on the comments from jessehouwing below, I think I can do the following:

enter image description here

enter image description here

like image 769
Richard Avatar asked Oct 17 '25 12:10

Richard


1 Answers

In your example, you have merged unwanted changes from development to autoapproval_hierarchy_ui

Problem:
I made a test environment where I merged 4 commits from dev to remote main My current Git Model. Now I want to revert dev changes from remote main!

Solution:
Go to your IntelliJ Idea:

  1. Understand where dev branch collides with main. From my Git Model Examle Git Model example it is where I have a commit: Merge pull request #1 from dev
  2. Make a left-click on that collision (now in the right bottom corner appeared a window)
  3. Hover over the root directory option and make right-click Image of this step
  4. Pick option: Revert Selected Changes
  5. Pop-up window can appear Example of a pop-up window. Select OK
  6. Now you have changes that will return main to the status before dev merge. Before dev merge.
  7. Now push this changes to remote main with the next commands:

git add .
git commit -m "YOUR COMMIT MESSAGE"
git push origin main

YOUR COMMIT MESSAGE - For example: Reverted last merge

Now you can see that main branch got rid of unwanted changes from dev branch: Final result

like image 72
Kalman Yudin Avatar answered Oct 20 '25 01:10

Kalman Yudin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!