1

With our Git setup, we have the following permanent branches: - Master |- Fixes-x.x - Release - Develop

Develop is where our in development code goes. When we are almost ready for "release", it's merged into "release" where we make any additional last minute changes before merging it into "master" and tag it with a version. If a bug is found in an older version we create a separate branch for it so it can be fixed and given a relevant version tag.

We have made a novice mistake where I inadvertently merged some experimental code into release (Which was based on develop), and then a workmate made a similar mistake shortly after where release was merged into a fixes branch. So release and fixes is pretty much a copy of our develop branch.

I want to go back, preferably by deleting the commit from history, since this wasn't a coding error but a complete mess up in merging. But i've been digging and can't find a clear way to do this with rebase. I can't find how to run rebase to list the commit I want to remove. It seems easy had we made this mistake in master.

Any suggestions for how to best recover from this is appreciated. These has been a couple of commits since then so they are not in the head.

2 Answers2

1

You can undo merge commits as any other commit with git reset. For instance, if you want to remove 1, 2 or 3 commits, a shorthand would be git reset HEAD~1, git reset HEAD~2, git reset HEAD~3respectively.

Until now you'd be editing your local commit tree. If you want to update a remote server, you'll have to execute git push --force (be careful, force flag can be the source of more problems).

As other developers could have pulled the problematic commit, it is possible that, since you'll be changing the branch head reference in the remote server, their git clients lost their track. So the easiest way for them to have a consistent copy again is to git clone the repo again. This is the cause why you should avoid using the --force flag. Of course there's plenty of other solutions to avoid having to clone everything again. But they're harder to explain and depend on particular situations.

Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55
0

I think my answer is here - Revert back changes made by merge

It doesn't mention rebase. Perhaps rebase is out of the question for this situation.

Community
  • 1
  • 1