dingo_d
dingo_d

Reputation: 11680

Fixing merge conflicts when merging to one branch, messes up commit on another branch

I have develop, master and a feature branch.

I made some changes on the feature branch and I made a PR on master. I also made a PR on develop which has changes that are not on the master branch.

It turned out that when I wanted to make PR on develop I had some conflicts so I fixed them on Github.

But what this basically did, was that develop was merged on my feature branch, and now my PR on master branch has all these commits from develop branch.

And I don't need that.

I tried using git revert but that didn't do anything on my feature branch.

Is there a way to remove this merge from the feature branch, or should I just close this PR and create a separate branch?

Branches look like this:

--------------master
  |     |
  |-----|-----------develop
        |------feature

I merged from master and made PR on develop and master from feature branch.

Not sure how I got the conflict, but develop branch has tons of stuff on it.

Upvotes: 0

Views: 104

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45789

It sounds like your workflow is a little more complicated / less linear than typical. That's not necessarily bad if it meets your needs, but you might want to see if something more structured (like gitflow) might also meet your needs, while making sure that most of the problems you face (and their solutions) are things more people will have experience with.

(While you're using some terms from gitflow, in gitflow you would not merge a feature directly to master. Of course you could have a hotfix from time to time, and those would merge directly to both master and develop, but in that case you'd probably merge to master first, knowing that (a) that's where the hotfix branch was split from, and (b) everything in master is already in develop.)

All of the above is fine and good, but for now you are where you are, and anyway you might look at it and decide that your workflow is the best one for your project... so how do you make this work?

So if I understand, you had

 A -- M <--(master)
     /   
... B -- C -- D <--(develop)

... E -- F <--(feature)

and you created a PR to integrate feature into develop, but there were conflicts - and to resolve those conflicts while allowing for review before develop would be updated, the resolution process merged into feature

 A -- M <--(master)
     /   
... B -- C -- D <--(develop)
               \
  ... E -- F -- X <--(feature)

There are many ways to fix this, but I'm going to assume that in your situation it'd be best to avoid history rewrites (i.e. avoid removing commits from the history of any published branch).

In that case, the simplest way forward is to create a new branch at F for the PR into master.

git checkout feature^
git branch feature_b

Upvotes: 2

Related Questions