0

I've been working in a branch, say master. Changes are already pushed to remote repository. My history looks like this:

*----*----*----* master

Then I realize that I may have done something wrong and want to start from a different approach. I do this by creating a new branch:

*----*----*----* master
     \
      *----*----* different-approach

After some new commits, I decide that the new approach works better than the one in the master branch, so I want to use that from now on on the master branch. So I do a merge:

git checkout master
git merge different-approach

In case there is any conflict, I always choose the version from the different-approach merge. The problem is that for some files there is no conflict, so git does an automatic merge leaving in the bad stuff from the master branch.

What can I do in this case? There seems to be no way to force a manual merge for all files in git. Of course I can clone the repository to a different directory and copy all files from it to the original directory before committing the merge. But isn't there a cleaner and simpler way to do this?

2 Answers 2

2

Fix it by reverting unwanted commits.

// Revert all commits in master one-by-one
$ git checkout master
$ git revert --no-edit different-approach..master
$ git merge different-approach

// Revert all commits in master at once
$ git checkout master
$ git revert --no-commit different-approach..master
$ git commit -m "Revert foo"
$ git merge different-approach
2
  • This might cause a problem if other people pushed changes to master. Their commits would be reverted as well.
    – gtrig
    Commented Jul 18, 2013 at 18:01
  • Well, I expect author is able to run any log viewer to confirm what he reverted. Commented Jul 18, 2013 at 22:22
-1

If you want to completely ignore the changes on master not on different-approach you can:

git checkout master
git reset --hard different-approach

Warning, this will completely wipe out changes on master not on different-approach.

2
  • My guess that it won't work if master is already pushed. At least it shouldn't. That's why I need a merge.
    – petersohn
    Commented Jul 17, 2013 at 14:18
  • Do you want to change master on remote as well? If so after the git reset --hard different-approach you can git push -f. Warning this does rewrite history on the remote so it seems the previous changes never happened.
    – cforbish
    Commented Jul 17, 2013 at 17:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.