2

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

Richard
  • 8,193
  • 28
  • 107
  • 228
  • Duplicate? https://stackoverflow.com/questions/61027235/how-to-revert-a-merge-commit-with-a-newer-commit-after-it/61029806#61029806 – jessehouwing Apr 07 '20 at 08:30
  • Does this answer your question? [How to revert a merge commit with a newer commit after it?](https://stackoverflow.com/questions/61027235/how-to-revert-a-merge-commit-with-a-newer-commit-after-it) – jessehouwing Apr 07 '20 at 08:30
  • @jessehouwing,Thanks. I am just having a look an trying to understand it. – Richard Apr 07 '20 at 08:34
  • @jessehouwing, please can you look my UPDATE above. Should I do an `Interactive Rebase from Here...`? (I don't need to keep the history). – Richard Apr 07 '20 at 08:44
  • I think you will have to use the revert option, or by-pass the branch protection to do a force-push. Rebase will be the cleaner option, but with branch protection in place, that's not an option. – jessehouwing Apr 07 '20 at 09:15
  • Yes, I am scared to do a rebase. I will try do a revert, but I am a bit confused of what exact command to use for my git based on your command: `git revert sha-of-2 -m X`. – Richard Apr 07 '20 at 09:21
  • I ended up just creating a new branch from the last commit I want to keep. – Richard Apr 07 '20 at 09:49

1 Answers1

0

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

Kalman Judin
  • 45
  • 1
  • 7