Question

My branch's history is as follows :

enter image description here

Now I want to revert merge with branch 558. I have it's sha code, so I'm doing :

git revert -m 1 1784adf300f43fb76391e92f80be01132eddb680

and the result is :

[master d51e2b3] Revert "Merge branch '558'" 1 files changed, 15 insertions(+), 29 deletions(-)

At this point when I try to push my revert back to origin, I see that only the last commit from merged 558 branch was reverted (as well as in the merge more than 1 file was affected). How can I revert all commits from the merged branch or am I doing something else wrong here.

Était-ce utile?

La solution

You can specify multiple commits, commit intervals using git revert. Here, you would need to find the first commit from branch 558 which diverged from master and the commit before the merge of the two branches.

Then, you can use:

git revert -n {first_commit}..{last_commit}

Here, the -n option allows not to have a commit for each reverted commit, it only stages the changes which you can commit with an appropriate description afterwards.

It should work if your history is simple, like in your example.

Correction and clarification: git won't accept directly a merge commit or an interval containing a merge for a revert. It is however possible to revert an entire branch using only the merge commit and the option -m i where i denotes which side of the merge to revert (starts from 1, so here it would be 2).

The whole issue is pretty delicate, and this document is an useful read about it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top