Skip to main content

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.

- Git Manual

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
  1. Double-check the files before going forward to make sure no bugs were introduced.

  2. 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.

  1. 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.
  2. 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:
    Note

    When looking for a commit ID, you can find the last instance where the missing file was in the repository.

  3. 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
  4. Stage and commit:

    git commit -am "verifying missing README.txt"

    You will receive confirmation from Git that the file has been committed.

  5. 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.

  1. 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:

    An example of Visual Studio Code highlighting a merge conflict

  2. Edit the conflict by choosing one of the two versions of the conflicting line(s), or by editing a version containing both updates.

  3. Remove all the delineator notes from the file.

  4. 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.

  1. 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.

  2. Edit the conflict by choosing one of the two content-hash values, or by editing a version containing both updates.

  3. Remove all the delineator notes from the file.

  4. 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.

  1. Navigate to your Dev environment > set the Development Mode to Git:

    Git Connection Mode

  2. Click Clone with Git to Clone the repository to your local computer:

    Git Clone

  3. Navigate to the repository directory, change to the master branch and pull the Multidev branch to master.

    • In the example below, replace multidev with the Multidev environment name:

      git checkout master
      git pull origin multidev
  4. Resolve the conflicts using the steps above when you receive the Git notification listing the files that are in conflict.

More Resources