Is there a good way to undo(or remove) a merge from history?
The original state:
* F main
|
* E
|
* D
|\ Merge: C 4
| |
| * 4 dev
| |
| * 3
| |
* | C
| |
| * 2
| |
| * 1
|/
* B
|
* A
After a undo(or remove) the merge, it would looks like:
* F main
|
* E
|
| * 4 dev
| |
| * 3
| |
* | C
| |
| * 2
| |
| * 1
|/
* B
|
* A
Or looks like:
* C E F main
|
| * 4 dev
| |
| * 3
| |
| * 2
| |
| * 1
|/
* B
|
* A
I have tried git rebase --onto C D main
, but there was a error:
error: Your local changes to the following files would be overwritten by checkout:
file1
file2
...
Please commit your changes or stash them before you switch branches.
Aborting
error: could not detach HEAD
I gave up this method since I don't know the dangers of advanced rebase applications. Finally, I reset the branch of main
hard to the commit of C, and add the E,F commits manually. I wonder if is there a good way to achieve this.