0

I have two git branches (master and fix_log_messages). I have been making various commits in the fix_log_messages branch and then periodically merging these changes/commits into master. As a result, the master branch contains multiple merges, due to the periodic merging of fix_log_messages branch into master branch.

I now need to remove all the commits which belong to fix_log_messages branch from master branch. In other words I need to undo multiple merges. I understand that I can revert a single merge using git revert -m 1 <merge-commit>. But what would be the workflow for removing multiple merges on a branch?

FYI - Changes to master have already been pushed to remote. All merges were performed using git merge --no-ff fix_log_messages.

Benjen
  • 2,835
  • 5
  • 28
  • 42
  • Are there commits on `master` other than the merge commits, and which you want to preserve? Or are the merges the only additional commits on `master`? The approach would be quite different for the two cases... – twalberg Nov 03 '15 at 21:42

1 Answers1

-1

You can use git log to see how many commits of your master branch you want to undo. If, for example, you want to rollback 6 commits, just type:

git reset --hard HEAD~6

If you want to recover your merged status, you can use reflog to see the commit id of the last commit in the original master branch, and then check it out.

Bustikiller
  • 2,423
  • 2
  • 16
  • 34
  • Unfortunately this will a) remove any non-merge commits on master within that range and b) break history if force-pushed to remote. – piersb Nov 14 '18 at 13:35