Azure DevOps pull request merge conflicts
When the source branch and the target branch of an Azure Repos pull request change the same lines differently, or one changes a file the other deletes, Azure DevOps cannot make the merge commit and the pull request stops at "conflicts". Below is what it shows and how to get the pull request moving again, from Microsoft's Complete, abandon, or revert pull requests, Resolve Git merge conflicts and the Pull Requests - Get reference.
What Azure DevOps shows
- The conflicting files are listed on the pull request's Overview page.
- Complete and auto-complete wait: the conflicts have to be resolved before the pull request can be merged or set to auto-complete. A pull request already set to auto-complete sends an email when a conflict keeps it from completing.
- The preview merge: More options (upper right of the Overview) > View merge changes shows the merge commit Azure DevOps would make. After changing the pull request's target branch, Restart merge makes a new preview merge.
- It tries again by itself: Azure DevOps runs a new merge every time the source branch changes, so pushing a resolution to the source branch is what clears the conflicts.
Resolving them on your machine
The usual route is to merge the target branch into the source branch locally, resolve the conflicts there and push. With the source branch feature and the target main:
git fetch origin
git checkout feature
git merge origin/main
# Git stops at "Automatic merge failed; fix conflicts and then commit the result."
# edit each conflicting file, then
git add <file> # or git rm <file> for a file deleted on one side
git merge --continue
git push
git statuslists the conflicting files andgit log --mergethe commits that conflict;git merge --abortgoes back to where you were.- In a conflicting file, the text between
<<<<<<<and=======is your branch's and the text between=======and>>>>>>>is the merged-in branch's. Removing the markers tells Git it is resolved. - You can rebase the source branch onto the target instead and push it; that rewrites the branch's commits, so the push has to replace them (
git push --force-with-lease), which needs the Force push permission on the branch. - Uncommitted changes in files the merge touches stop it ("Your local changes to the following files would be overwritten by merge"): commit or stash them first.
Resolving them in the browser
The web page lists the conflicts but has no editor for them. Microsoft DevLabs' Pull Request Merge Conflict Extension, installed into the organization from the Visual Studio Marketplace, adds a Conflicts tab to the pull request: pick a file, choose how to resolve it, edit it in the editor of VS Code (Monaco) and submit it. Its listing names the known issues: files over 8 MB may only take the whole source or target file, only files with detected conflicts can be edited, directory/file conflicts are not supported, and updates to conflicted files do not show in the Files tab. DevLabs describes its extensions as experiments that are not supported. And after resolving with it, the pull request cannot be completed with a rebase merge type: Microsoft says conflict resolutions applied to a three-way merge are seldom valid when the commits are rebased one by one. Rebase locally and push, or squash.
From the REST API
mergeStatusonGET …/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}is the status of the pull request's merge:conflicts("merge failed due to conflicts"),succeeded,queued,rejectedByPolicy,failureornotSet.lastMergeCommitis the commit of the most recent merge; empty, that merge is in progress or did not succeed.lastMergeSourceCommitandlastMergeTargetCommitare the branch heads it was made from.- A merge that fails for another reason sets
mergeFailureMessage, andmergeFailureTypecan saycaseSensitive(a case mismatch) orobjectTooLarge.
Merge conflicts in IntelliJ IDEA
Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, lists the pull requests of Azure DevOps Services and Azure DevOps Server in an IDE tool window. From version 1.0.57, a pull request with merge conflicts says so at the top of its Overview, with Resolve in the IDE: it fetches, checks out the source branch and merges the target branch into it, so the conflicting files open in the IDE's merge dialog (Accept Yours, Accept Theirs, or Merge… side by side). From 1.0.60 the Overview first lists the files in conflict and what clashes in each (changed on both sides, deleted on one side, added on both sides, renamed differently, a file against a folder), as Azure DevOps reports them for the pull request. Commit the merge and push the branch, and Azure DevOps tries the merge again. Resolving conflicts is free, as are the review inbox, the diff and the branch policies; voting, commenting, completing and creating pull requests are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Azure DevOps is a trademark of Microsoft Corporation; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.
More: auto-complete and optional policies · merge types · build validation · 日本語