マージの競合を解決する

このページの内容

Still need help?

アトラシアン コミュニティをご利用ください。

コミュニティへの質問

このページの内容

We're in the process of updating Bitbucket's pull request experience. As a result, you may only see content conflicts right now. We're working on displaying all types of conflicts. To get immediate access to all conflict types for an individual pull request, go to > Open in old view.

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 between Git branches

These steps include details for resolving conflicts between two branches in a Git repository. You'll see references to these placeholders:

  • The directory to the forked repository as <repo_directory>
  • The destination branch as <destination_branch>
  • The source branch as <feature_branch>
  • The file with resolved conflicts as <filename>
詳細を展開
  1. Make sure you're in your repository directory.

    $ cd ~/<repo_directory>

    For example, if your repository name is my-repository, 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 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>

    For example, if your destination branch is master, 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 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 between Git forks

These steps include details for resolving conflicts between a forked repository and its original Git repository. You'll see references to these placeholders:

  • The directory to the forked repository as <repo_directory>
  • The URL of the original repository as <original_repo_URL>
  • The file with resolved conflicts as <filename>
  • The destination branch of the forked repository as <destination_branch>

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 there, which automatically merges the pull request when you push.

詳細を展開
  1. Make sure you're in your forked repository directory.

    $ cd ~/<repo_directory>

    For example, if your repository name is my-repository, the result might look something like this:

    computer:$ cd ~/my-repository
    computer:my-repository$
  2. 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


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

      結果は次のようになります。

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

  5. 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:
  6. Add and commit the change.

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

    $ git push origin <destination_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 between Mercurial branches

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

詳細を展開
  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 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 between Mercurial forks

These steps include details for resolving conflicts between a forked repository and its original repository using Sourcetree. To resolve conflicts for a Mercurial repository, you'll need to install and use an additional merge tool. 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 there, which automatically merges the pull request when you push.

詳細を展開
  1. Open the forked repository in Sourcetree.

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

  3. To pull the most recent version of the original repository, click the Pull button again. From the open dialog:
    1. From Pull this repository, select Custom and enter the URL to the original repository.
    2. OK をクリックします。
  4. 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.

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

  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. Go back to Sourcetree, and select the Uncommitted changes line from the History.
  8. 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.

最終更新日 2018 年 5 月 22 日

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

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