petersohn
petersohn

Reputation: 11730

Reverting branch in git

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?

Upvotes: 0

Views: 199

Answers (2)

the.malkolm
the.malkolm

Reputation: 2421

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

Upvotes: 2

cforbish
cforbish

Reputation: 8819

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.

Upvotes: -1

Related Questions