1

A little background:

master branch of code base

dev branch of code base

both are being worked on (I know, but I just started on this project so I'm not to blame)

at one point, dev was mistakenly merged back into master, then a few commits later all those changes were reverted (manually, it looks like)

Now, I need to merge dev back into master for real, but all the changes that were accidentally merged and then reverted are, of course, missing.

I'm not quite sure what to do here other than manually making the changes after the merge.

Any thoughts?

Jakanapes
  • 75
  • 7

2 Answers2

1

I would suggest an interactive rebase. Delete the commit that reverted the changes and fix any merge conflicts.

Stefan
  • 109,145
  • 14
  • 143
  • 218
  • I was trying to avoid rebase, but it makes the most sense. The problem is really the lack of workflow that led to the situation in the first place, so this is the best solution. – Jakanapes Jun 01 '12 at 19:37
1

The wonderful thing about git is its flexibility and how hard it is to actually delete something.

Here's one way to approach it:

git checkout master
git log (make note of all commits on master that you want which were done after the incorrect merge)
git reset --hard <commit before dev was merged in in error>
git cherry-pick <id's of commits previously identified>
git merge develop (to do the desired merge)

As was mentioned in the other answer, an interactive-rebase is an option too. You can use that to drop the commit that introduced the bad merge and the commits which reverted it.

Note that you'll be rewriting history, so you're going to have to push to a shared repository with --force and let the other developers know so they can re-clone, or pull the changes into a new branch, etc. Making sure to coordinate with the team before proceeding with these changes is important.

wadesworld
  • 13,535
  • 14
  • 60
  • 93
  • Good idea, I like the cherry-pick, but after discussion, the team is going with rebase. I'll definitely keep this method in mind for the future, though – Jakanapes Jun 01 '12 at 19:36