Resolve Merge Conflicts
Learn how to resolve conflicts in your site code base.
Conflicts can occur when modified file(s) within your site's codebase do not align with changes made to the same file(s) in the site's upstream.
When a merge isn’t resolved automatically, Git leaves the index and the working tree in a special state that gives you all the information you need to help resolve the merge.
Resolve Conflicts When Updating Core
The fastest resolution for conflicts when updating is often to use the -Xtheirs
flag. This will attempt to automatically resolve the conflicts with a preference for upstream changes.
This is safe to run if you don't have your own changes in any of the conflicting files (for example problems with .gitignore
).
git pull -Xtheirs https://github.com/pantheon-systems/drops-7.git master
# resolve conflicts
git push origin master
git pull -Xtheirs https://github.com/pantheon-upstreams/drupal-composer-managed.git main
# resolve conflicts
git push origin master
git pull -Xtheirs https://github.com/pantheon-upstreams/drupal-10-composer-managed.git main
# resolve conflicts
git push origin master
git pull -Xtheirs https://github.com/pantheon-systems/WordPress.git master
# resolve conflicts
git push origin master
git pull -Xtheirs https://github.com/pantheon-systems/wordpress-network.git master
# resolve conflicts
git push origin master
Double-check the files before going forward to make sure no bugs were introduced.
- The
-Xtheirs
flag will drop your changes if you modify core CMS files. You should manually resolve conflicts in this scenario.
- The
Review WordPress and Drupal Core Updates for more details on core updates.
Find a Site's Upstream URL
Run the following command in Terminus to retrieve your Upstream URL:
terminus site:info <site> --field=upstream
Manually Resolve Conflicts
Steps to resolve merge conflicts vary by the type of conflict. Refer to the sections below for more information on resolving delete/modify conflicts, content conflicts, and Multidev conflicts.
Resolve Delete/Modify Conflicts
A delete/modify conflict occurs when one commit deletes a file and another modifies it. Follow the steps below to resolve such a conflict.
Identify the file that is generating a delete error.
For example, the Git log may contain an entry similar to the following:
CONFLICT (delete/modify): scripts/run-tests.sh deleted in HEAD and modified in 72faeeff1c9356221694d1351cdb2000ab3c5d1c. Version 72faeeff1c9356221694d1351cdb2000ab3c5d1c of scripts/run-tests.sh left in tree.
Navigate to your local repository > run the following Git command to get a copy of the file in conflict:
git checkout <commit ID> -- <file>
Info:NoteWhen looking for a commit ID, you can find the last instance where the missing file was in the repository.
Run
git status
and verify that there is a new file to add to the repository:git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) new file: README.txt
Stage and commit:
git commit -am "verifying missing README.txt"
You will receive confirmation from Git that the file has been committed.
Run the Git push command:
git push origin master
Resolve Content Conflicts
A content conflict occurs when two commits modify the same line(s) of a file non-sequentially (without one having the other in its history). For example:
CONFLICT (content): Merge conflict in wp-admin/about.php
Automatic merge failed; fix conflicts and then commit the result.
Follow the steps below to resolve this scenario.
Open the conflicting file in your text editor or IDE. Note that the conflicting lines are enclosed with
< HEAD
at the top, and> <commit-id>
at the bottom, with=======
delineating the two versions. Some IDEs, like Visual Studio Code for example, will highlight the conflicting section:Edit the conflict by choosing one of the two versions of the conflicting line(s), or by editing a version containing both updates.
Remove all the delineator notes from the file.
Commit and push your changes:
git add wp-admin/about.php git commit -m "Merge conflict resolution" git push origin master
Resolve Conflicts on Drupal Composer-Managed Sites
A content conflict shows in the content-hash section of your composer.lock
file. This type of merge conflict happens when two developers install or remove the package(s) in different branches. The branches cannot be merged because the composer.lock
file has two different content-hash values.
Open the conflicting file in your text editor or IDE. Note that the conflicting lines are enclosed with
< HEAD
at the top, and> <commit-id>
at the bottom, with=======
delineating the two versions.Edit the conflict by choosing one of the two content-hash values, or by editing a version containing both updates.
Remove all the delineator notes from the file.
Run the command below:
$ composer update --lock
Resolve Conflicts from Multidevs
Follow the steps below to resolve a merge conflict that is preventing you from merging a Multidev environment.
Navigate to your Dev environment > set the Development Mode to Git:
Click Clone with Git to Clone the repository to your local computer:
Navigate to the repository directory, change to the
master
branch and pull the Multidev branch tomaster
.In the example below, replace
multidev
with the Multidev environment name:git checkout master git pull origin multidev
Resolve the conflicts using the steps above when you receive the Git notification listing the files that are in conflict.