pdace
pdace

Reputation: 35

Git: Reverting An Old Merge Without Affecting the Rest of The Commits

When I go to the commit I want to revert (Reverse Commit) it gives me

error: commit X is a merge but no -m option was given.

It is like an 3 weeks old commit and lots of other people pushed other things after that merge. I want to delete the changes made in that merge without causing tons of conflicts.

If I reset to the commit before it (Commit Y), everything after this will be gone and If I push it that way, I'm assuming there would be lots of conflicts if anyone changed anything in the files that exist in that commit (in Y not X).

Is there any clean, and hopefully easy, way of doing this? Sorry if I'm assuming incorrect things, I'm a git newbie. Please go easy on me.

Upvotes: 2

Views: 45

Answers (1)

Andy
Andy

Reputation: 30428

You don't want to use git reset because that will rewrite history that has already been pushed. That should be avoided if at all possible.

The error message is telling you want to do: the -m option tells git which of the two parent commits you want to keep so that it can revert the other:

git revert -m 1 <hash of the merge commit>

Note that if you will want to merge the changes from this merge commit back in at some point in the future, you will need to revert this commit (i.e. the commit that reverted the changes) and then merge everything in again.

The blog post Undoing Merges has more information about this, and likely explains it better than I have.

Upvotes: 2

Related Questions