Resolve merge conflicts

このページの内容

Still need help?

The Atlassian Community is here for you.

コミュニティへの質問

このページの内容

When you create a pull request Bitbucket automatically compares the source with your update and the destination with the original code. If anyone else has made changes in the destination to the same code you touched, we'll notify you of conflicts when you attempt to merge.

When you have merge conflicts, you can't click the Merge button from the pull request to merge. To resolve these conflicts, you pull the changes to your local repository and fix them there. Merge conflicts may look something like this:

Resolving the conflict with Git branches

These steps include details for dealing with conflicts between branches in a Git repository, as well as forked versions of a repository. They refer to the destination branch as destination_branch and the source branch as feature_branch.

Expand for details
  1. Make sure you're in your repository directory.

    $ cd ~/<repo-directory>

    The result might look something like this:

    computer:$ cd ~/my-repository
    computer:my-repository emmap$
  2. Pull the most recent version of the repository from Bitbucket.

    $ git pull
  3. Checkout the source branch.

    $ git checkout <feature_branch>
  4. Pull the destination branch (which may or may not be master) into the source branch. At this point, pulling the destination will try to merge it with the source and reveal all the conflicts.

    $ git pull origin <destination_branch>

    The result will look something like this:

    computer:my-repository emmap$ git pull origin master
     * branch            master     -> FETCH_HEAD
    Auto-merging team_contact_info.txt
    CONFLICT (content): Merge conflict in team_contact_info.txt
    Automatic merge failed; fix conflicts and then commit the result.

    When you merge two branches with conflicts locally, you'll get conflict markers in the file when you open your favorite editor.

  5. Open the file to resolve the conflict. You can do this using the command line or you can navigate to the file.
    The file will look something like this:

    A. The beginning of the change in the HEAD branch. In this case, HEAD represents the active branch into which you're merging.
    B. The end of the change in the active branch and the beginning of the change in the non-active branch.
    C. The end of the change in the non-active branch.

  6. Resolve the conflict by doing the following:
    1. Remove the change designations added by Git (AB, and C in the screenshot above).
    2. Correct the content.
    3. Save the file.
      The result will look something like this:
  7. Add and commit the change.

    $ git add <filename>
    $ git commit -m'commit message'
  8. Push the change to the remote.

    git push origin <feature_branch>

When you check the pull request, the pull request will still be open and you'll no longer see any merge conflicts.

Resolving the conflict with Git forks

These steps include details for dealing with conflicts between forks in a Git repository.

These instructions describe how to resolve conflicts in the forked repository by pulling updates from the original repository. Alternatively, you can pull the forked repository into the original repository to resolve conflicts in the original repository, causing the pull request to automatically merge with you push.

Expand for details
  1. Make sure you're in your forked repository directory.

    $ cd ~/<repo-directory>

    The result might look something like this:

    computer:$ cd ~/my-repository
    computer:my-repository emmap$


    If anyone else has been working on the forked repository, make sure you've got the most recent version of the repository from Bitbucket.

    $ git pull
  2. Pull the destination repository to your local repository to merge it with the forked repository.

    1. From the repository, copy the URL.
    2. Enter the repository URL with git pull at the command line:

      $ git pull <original_repo_URL>

      The result will look something like this:

      computer:my-repository emmap$ git pull git@bitbucket.org:user/myteamquotes.git
      remote: Counting objects: 219, done.
      remote: Compressing objects: 100% (219/219), done.
      remote: Total 219 (delta 137), reused 0 (delta 0)
      Receiving objects: 100% (219/219), 565.11 KiB | 382.00 KiB/s, done.
      Resolving deltas: 100% (137/137), completed with 2 local objects.
      From bitbucket.org:tutorials/tutorials.git.bitbucket.org
       * branch            HEAD       -> FETCH_HEAD
      Auto-merging editme.html
      CONFLICT (content): Merge conflict in editme.html
      Automatic merge failed; fix conflicts and then commit the result.
  3. Open the file to resolve the conflict. You can do this using the command line or you can navigate to the file.
    The file will look something like this:

    A. The beginning of the change in the HEAD branch. In this case, HEAD represents the active branch into which you're merging. 
    B. The end of the change in the active branch and the beginning of the change in the non-active branch.
    C. The end of the change in the non-active branch.

  4. Resolve the conflict by doing the following:
    1. Remove the change designations added by Git (AB, and C in the screenshot above).
    2. Correct the content.
    3. Save the file.
      The result will look something like this:
  5. Add and commit the change.

    $ git add <filename>
    $ git commit -m'commit message'
  6. Push the change to the destination repository.

    git push origin master

When you check the pull request, the pull request will still be open and you'll no longer see any merge conflicts.

Resolving the conflict with Mercurial branches

To resolve conflicts for a Mercurial repository, you'll need to install and use an additional merge tool. These steps include details for resolving conflicts with SourceTree (and refer to the destination branch as destination_branch and the source branch as feature_branch). Start by installing SourceTree if you don't have it yet.

Expand for details
  1. Open the repository in SourceTree.

  2. From the repository, make sure you're on the source branch. Under Branches, you'll see the branch you've got checkout out in bold. If the source branch isn't checked out, double-click the branch name.

  3. Click the Pull button to pull the most recent version of the repository from Bitbucket. From the open dialog, keep the default and click OK.

  4. Merge the two branches with conflicts:
    1. Click the most recent commit from the source branch.
    2. マージ ボタンをクリックします。
    3. Click the most recent commit from the destination branch.
    4. Click OK from the dialog.
  5. You'll get a Merge Conflicts dialog because pulling the source will try to merge it with the destination repository and reveal all the conflicts. Click OK.

  6. Open the file with your favorite editor to resolve the conflict.
    The file will look something like this:

    A. The beginning of the change in the active branch.
    B. The end of the change in the active branch and the beginning of the change in the non-active branch.
    C. The end of the change in the non-active branch.

  7. Resolve the conflict by doing the following:
    1. Remove the change designations added by Git (AB, and C in the screenshot above).
    2. Correct the content.
    3. Save the file.
      The result will look something like this:
  8. Go back to SourceTree, and select the file with conflicts. From Actions, select Resolve Conflicts and then select Mark Resolved. From the dialog, click OK.
  9. Click the Commit button, enter a commit message, and click Commit.
  10. Click the Push button, go with everything that's already selected, and click OK.

When you check the pull request, the pull request will still be open and you'll no longer see any merge conflicts.

Resolving the conflict with Mercurial forks

To resolve conflicts for a Mercurial repository, you'll need to install and use an additional merge tool. These steps include details for resolving conflicts with SourceTree. Start by installing SourceTree if you don't have it yet.

These instructions describe how to resolve conflicts in the forked repository by pulling updates from the original repository. Alternatively, you can pull the forked repository into the original repository to resolve conflicts in the original repository, causing the pull request to automatically merge with you push.

Expand for details
  1. Open the forked repository in SourceTree.

  2. If anyone else has been working on the forked repository, click the Pull button to make sure you've got the most recent version of the repository from Bitbucket.

  3. From the forked repository, click the Pull button to pull the most recent version of the destination branch from Bitbucket. From the open dialog, go with the default options and click OK.

  4. Click the Pull button to pull the most recent version of the original repository from Bitbucket. From the open dialog:
    1. From Pull this repository, select Custom and enter the URL to the original repository.
    2. OK をクリックします。
  5. You'll get a Merge Conflicts dialog because pulling the source will try to merge it with the destination repository and reveal all the conflicts. Click OK.

  6. Open the file with your favorite editor to resolve the conflict.

    The file will look something like this:

    A. The beginning of the change in the active branch.
    B. The end of the change in the active branch and the beginning of the change in the non-active branch.
    C. The end of the change in the non-active branch.

  7. Resolve the conflict by doing the following:
    1. Remove the change designations added by Git (AB, and C in the screenshot above).
    2. Correct the content.
    3. Save the file.
      The result will look something like this:
  8. Go back to SourceTree, and select the Uncommitted changes line from the History.
  9. From Actions, select Resolve Conflicts and then select Mark Resolved. From the dialog, click OK.
  10. Click the Commit button, enter a commit message, and click Commit.
  11. Click the Push button, go with everything that's already selected, and click OK.

When you check the pull request, the pull request will still be open and you'll no longer see any merge conflicts.

最終更新日: 2018 年 2 月 13 日

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.