75

I've created pull request I got into this:

enter image description here

"Approve" button does nothing and complete is disabled.

How do I resolve this confligt in pull request?

5 Answers 5

67

Update

Microsoft just added browser based merges. This may get you out of a pickle for small conflicts.

And offers improved visualizations of the different scenarios as of Sprint 150.

For more complex situations:

You have two options to resolve the conflict, reverse-integrate the changes from the target branch (which creates additional merge commits), or rebase on the target branch (which leaves your history nice and clean).


Merge from target to current branch prior to completing the PR.

You need to clone the repo locally, perform a merge from the target branch to your branch and push those changes up to the repository. VSTS will detect the changes and update the pull request.

            -------o3              PR
           /
---------o1-o2                     target

Thus merge target (o2) to PR:

            -------o3-o4           PR
           /          /
---------o1----------o2            target

Then complete the PR

            -------o3-o4           PR
           /          / \
---------o1----------o2--o5        target

Rebase the PR branch to include the latest changes on target

Alternatively, you can clone the repo locally, rebase the PR branch on the latest version of the target branch, solve all issues from the rebase and force-push the changes back to the PR branch. VSTS will detect the changes and update the pull request.

            -------o3              PR
           /
---------o1-o2                     target

Thus rebase o3 onto o2:

              -------o3            PR
             /
---------o1-o2                     target

Then complete the PR (with Fast-forward merge in the case below):

---------o1-o2-o3                  target
1
  • 1
    From where do you initiate the browser based merge? Complete button is disabled.
    – RBT
    Dec 27, 2021 at 5:02
35
  1. Open your project with Visual Studio.
  2. Open View > Team Explorer
  3. Change to Branches tab.
  4. Double click to the branch you intend to merge (e.g. dev).
  5. Right Click > Merge From > Select
    Merge from branch: master,
    Into current branch: dev
  6. Click Merge button
  7. Choose the conflict file(s)
  8. Then resolve the conflicts. You can click the left or right checkbox for the section you want to include.
  9. Then commit the merge
  10. Done.

To answer @metabuddy's question:

And then what? This only shows how to resolve conflicts locally, I can't push the target nor source branch directly to VSTS because I have branch policies which require pull requests to be made from feature branches.

You can follow the steps above. Just the source branch and target branch will be slightly different.

  1. branch merge from: master
  2. branch into: your-feature-branch
  3. Create Pull Request to merge from your-feature-branch into master
4
  • 10
    And then what? This only shows how to resolve conflicts locally, I can't push the target nor source branch directly to VSTS because I have branch policies which require pull requests to be made from feature branches. Feb 4, 2019 at 7:56
  • 2
    @metabuddy: Author of this answer assumed, you are merging dev into master. If you have pull request from feature branch into dev, you can locally merge dev into your feature branch, resolve conflict and push feature branch.
    – Liero
    Oct 1, 2020 at 7:30
  • If I make a pull request from my-feature-branch to master (after merging the conflicts), I cannot continue because there are no differences between the two branches. That somehow renders PRs obsolete. Nov 9, 2020 at 12:35
  • For VS 2019 the navigation is little different. Once you've selected dev branch, then right click on Master and select Merge into Current Branch option from the context menu.
    – RBT
    Dec 27, 2021 at 5:21
10

You could do the above technique by @jessiehouwing or use the new plug-in. MicrosoftDevLabs released the link to the plugin to resolve conflicts. The link to plugin is given below https://marketplace.visualstudio.com/items?itemName=ms-devlabs.conflicts-tab

1
  • 1
    After following the steps in the link and getting to the "Accept merge" stage, I don't see any merge commits. How can I keep developing at this point? Is merging the PR pretty much my only option at this point?
    – s g
    Aug 9, 2018 at 1:41
0

This answer is in reference of comment by @metabuddy on the answer of @sky91

What if your target branch in 'master' and on 'master' branch you have the policies applied to not accept direct merges?

Note: Consider 'master' is target branch and 'x001' is the source branch in pull request, which has conflicts between 'master' and 'x001' branch.

In that case solution by @sky91 will not work. For this you to follow these steps.

  1. Create a new branch from target ('master') branch, like 'x002'
  2. Go to visual studio, and select 'x002'
  3. Merge 'x002' from 'x001' branch.
  4. Go to your pull request and change the target branch to 'x002'
  5. It will show the same conflicts as you have in the pull request.
  6. Resolve all the conflicts and commit the merge.
  7. When you refresh the pull request page, it will show that 'changes already merge'
  8. It must show 'Close' button. if it is there, then close this pull request.
  9. Now all your changes has been merged and saved to 'x002'
  10. Create a new pull request from 'x002' to 'master'
  11. Because all the conflicts are gone, it will allow merging into 'master' branch.
2
  • Why not just merge master into x001, in order to resolve conflicts?
    – Liero
    Oct 1, 2020 at 7:26
  • At some point, this was not possible in my case. The above one was the cleanest way to go. Oct 1, 2020 at 13:39
0

After some failed attempts, I found works solution, Based on @Sailesh answer in Merge development branch with master question:

Start with merge master into the development so that if there are any conflicts, you can resolve in the development branch itself

(on branch development)$ git merge master

After this you can complete the Pull Request in the opposite direction without problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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