

# Working with pull requests in AWS CodeCommit repositories
<a name="pull-requests"></a>

A pull request is the primary way you and other repository users can review, comment on, and merge code changes from one branch to another. You can use pull requests to collaboratively review code changes for minor changes or fixes, major feature additions, or new versions of your released software. Here is one possible workflow for a pull request:

Li Juan, a developer working in a repo named MyDemoRepo, wants to work on a new feature for an upcoming version of a product. To keep her work separate from production-ready code, she creates a branch off of the default branch and names it *feature-randomizationfeature*. She writes code, makes commits, and pushes the new feature code into this branch. She wants other repository users to review the code for quality before she merges her changes into the default branch. To do this, she creates a pull request. The pull request contains the comparison between her working branch and the branch of the code where she intends to merge her changes (in this case, the default branch). She can also create an approval rule that requires a specified number of users to approve her pull request. She can even specify an approval pool of users. Other users review her code and changes, adding comments and suggestions. She might update her working branch multiple times with code changes in response to comments. Her changes are incorporated into the pull request every time she pushes them to that branch in CodeCommit. She might also incorporate changes that have been made in the intended destination branch while the pull request is open, so users can be sure they're reviewing all of the proposed changes in context. When she and her reviewers are satisfied, and the conditions for approval rules (if any) have been satisfied, she or one of her reviewers merges her code and closes the pull request. 

![\[Creating a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-create.png)


Pull requests require two branches: a source branch that contains the code you want reviewed, and a destination branch, where you merge the reviewed code. The source branch contains the AFTER commit, which is the commit that contains the changes you want to merge into the destination branch. The destination branch contains the BEFORE commit, which represents the state of the code before the pull request branch is merged into the destination branch. The choice of merge strategy affects the details of how commits are merged between the source and destination branches in the CodeCommit console. For more information about merge strategies in CodeCommit, see [Merge a pull request (console)](how-to-merge-pull-request.md#how-to-merge-pull-request-console).

![\[The source and destination branches for a pull requests, showing the relationship between before and after commits\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-concepts.png)


The pull request displays the differences between the tip of the source branch and the latest commit on the destination branch when the pull request is created, so users can view and comment on the changes. You can update the pull request in response to comments by committing and pushing changes to the source branch. 

![\[Adding a comment on a line in a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-comment.png)


When your code has been reviewed, and the approval rule requirements (if any) have been satisfied, you can close the pull request in one of several ways: 
+ Merge the branches locally and push your changes. This closes the request automatically if the fast-forward merge strategy is used and there are no merge conflicts.
+ Use the AWS CodeCommit console to close the pull request without merging, resolve conflicts in a merge, or, if there are no conflicts, close and merge the branches using one of the available merge strategies.
+ Use the AWS CLI.

Before you create a pull request:
+ Make sure that you have committed and pushed the code changes you want reviewed to a branch (the source branch).
+ Set up notifications for your repository, so other users can be notified about the pull request and changes to it. (This step is optional, but recommended.)
+ Create and associate approval rule templates with your repository, so that approval rules are automatically created for pull requests to help ensure code quality. For more information, see [Working with approval rule templates](approval-rule-templates.md).

Pull requests are more effective when you've set up IAM users for your repository users in your Amazon Web Services account. It's easier to identify which user made which comment. The other advantage is that IAM users can use Git credentials for repository access. For more information, see [Step 1: Initial configuration for CodeCommit](setting-up-gc.md#setting-up-gc-account). You can use pull requests with other kinds of users, including federated access users.

For information about working with other aspects of your repository in CodeCommit, see [Working with repositories](repositories.md), [Working with approval rule templates](approval-rule-templates.md), [Working with files](files.md), [Working with commits](commits.md), [Working with branches](branches.md), and [Working with user preferences](user-preferences.md). 

**Topics**
+ [

# Create a pull request
](how-to-create-pull-request.md)
+ [

# Create an approval rule for a pull request
](how-to-create-pull-request-approval-rule.md)
+ [

# View pull requests in an AWS CodeCommit repository
](how-to-view-pull-request.md)
+ [

# Review a pull request
](how-to-review-pull-request.md)
+ [

# Update a pull request
](how-to-update-pull-request.md)
+ [

# Edit or delete an approval rule for a pull request
](how-to-edit-delete-pull-request-approval-rule.md)
+ [

# Override approval rules on a pull request
](how-to-override-approval-rules.md)
+ [

# Merge a pull request in an AWS CodeCommit repository
](how-to-merge-pull-request.md)
+ [

# Resolve conflicts in a pull request in an AWS CodeCommit repository
](how-to-resolve-conflict-pull-request.md)
+ [

# Close a pull request in an AWS CodeCommit repository
](how-to-close-pull-request.md)

# Create a pull request
<a name="how-to-create-pull-request"></a>

Creating pull requests helps other users see and review your code changes before you merge them into another branch. First, you create a branch for your code changes. This is referred to as the source branch for a pull request. After you commit and push changes to the repository, you can create a pull request that compares the contents of that branch (the source branch) to the branch where you want to merge your changes after the pull request is closed (the destination branch). 

You can use the AWS CodeCommit console or the AWS CLI to create pull requests for your repository. 

**Topics**
+ [

## Create a pull request (console)
](#how-to-create-pull-request-console)
+ [

## Create a pull request (AWS CLI)
](#how-to-create-pull-request-cli)

## Create a pull request (console)
<a name="how-to-create-pull-request-console"></a>

You can use the CodeCommit console to create a pull request in a CodeCommit repository. If your repository is [configured with notifications](how-to-repository-email.md), subscribed users receive an email when you create a pull request.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to create a pull request. 

1. In the navigation pane, choose **Pull Requests**.
**Tip**  
You can also create pull requests from **Branches** and **Code**.

1. Choose **Create pull request**.   
![\[Creating a pull request from the Pull requests page in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view.png)

1. In **Create pull request**, in **Source**, choose the branch that contains the changes you want reviewed. 

1. In **Destination**, choose the branch where you intend to merge your code changes when the pull request is closed. 

1. Choose **Compare**. A comparison runs on the two branches, and the differences between them are displayed. An analysis is also performed to determine whether the two branches can be merged automatically when the pull request is closed.

1. Review the comparison details and the changes to be sure that the pull request contains the changes and commits you want reviewed. If not, adjust your choices for source and destination branches, and choose **Compare** again.

1. When you are satisfied with the comparison results for the pull request, in **Title**, enter a short but descriptive title for this review. This is the title that appears in the list of pull requests for the repository. 

1. (Optional) In **Description**, enter details about this review and any other useful information for reviewers.

1. Choose **Create**.  
![\[Creating a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-create.png)

Your pull request appears in the list of pull requests for the repository. If you [configured notifications](how-to-repository-email.md), subscribers to the Amazon SNS topic receive an email to inform them of the newly created pull request.

## Create a pull request (AWS CLI)
<a name="how-to-create-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

**To use the AWS CLI to create a pull request in a CodeCommit repository**
+ Run the **create-pull-request** command, specifying:
  + The name of the pull request (with the **--title** option).
  + The description of the pull request (with the **--description** option).
  + A list of targets for the **create-pull-request** command, including:
    + The name of the CodeCommit repository where the pull request is created (with the **repositoryName** attribute).
    + The name of the branch that contains the code changes you want reviewed, also known as the source branch (with the **sourceReference** attribute).
    + (Optional) The name of the branch where you intend to merge your code changes, also known as the destination branch, if you do not want to merge to the default branch (with the **destinationReference** attribute).
  + A unique, client-generated idempotency token (with the **--client-request-token** option). 

  This example creates a pull request named *Pronunciation difficulty analyzer* with a description of *Please review these changes by Tuesday* that targets the *jane-branch* source branch. The pull request is to be merged into the default branch *main* in a CodeCommit repository named `MyDemoRepo`:

  ```
  aws codecommit create-pull-request --title "Pronunciation difficulty analyzer" --description "Please review these changes by Tuesday" --client-request-token 123Example --targets repositoryName=MyDemoRepo,sourceReference=jane-branch 
  ```

# Create an approval rule for a pull request
<a name="how-to-create-pull-request-approval-rule"></a>

Creating approval rules for your pull requests helps ensure the quality of your code by requiring users to approve the pull request before the code can be merged into the destination branch. You can specify the number of users who must approve a pull request. You can also specify an approval pool of users for the rule. If you do so, only approvals from those users count toward the number of required approvals for the rule. 

**Note**  
You can also create approval rule templates, which can help you automate the creation of approval rules across repositories that will apply to every pull request. For more information, see [Working with approval rule templates](approval-rule-templates.md).

You can use the AWS CodeCommit console or the AWS CLI to create approval rules for your repository. 

**Topics**
+ [

## Create an approval rule for a pull request (console)
](#how-to-create-pull-request-approval-rule-console)
+ [

## Create an approval rule for a pull request (AWS CLI)
](#how-to-create-pull-request-approval-rule-cli)

## Create an approval rule for a pull request (console)
<a name="how-to-create-pull-request-approval-rule-console"></a>

You can use the CodeCommit console to create an approval rule for a pull request in a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to create an approval rule for a pull request. 

1. In the navigation pane, choose **Pull Requests**.

1. Choose the pull request for which you want to create an approval rule from the list. You can only create approval rules for open pull requests.  
![\[A list of pull requests for a repository in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view.png)

1. In the pull request, choose **Approvals**, and then choose **Create approval rule**. 

1. In **Rule name**, give the rule a descriptive name so you know what it is for. For example, if you want to require two people to approve a pull request before it can be merged, you might name the rule **Require two approvals before merge**. 
**Note**  
You cannot change the name of an approval rule after you create it.

   In **Number of approvals needed**, enter the number you want. The default is 1.   
![\[Creating an approval rule for a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-create-approval-rule.png)

1. (Optional) If you want to require that the approvals for a pull request come from a specific group of users, in **Approval rule members**, choose **Add**. In **Approver type**, choose one of the following: 
   + **IAM user name or assumed role**: This option prepopulates the AWS account ID with the account you used to sign in, and only requires a name. It can be used for both IAM users and federated access users whose name matches the provided name. This is a very powerful option that offers a great deal of flexibility. For example, if you are signed in with the Amazon Web Services account 123456789012 and choose this option, and you specify **Mary\$1Major**, all of the following are counted as approvals coming from that user:
     + An IAM user in the account (`arn:aws:iam::123456789012:user/Mary_Major`)
     + A federated user identified in IAM as Mary\$1Major (`arn:aws:sts::123456789012:federated-user/Mary_Major`)

     This option would not recognize an active session of someone assuming the role of **CodeCommitReview** with a role session name of Mary\$1Major (`arn:aws:sts::123456789012:assumed-role/CodeCommitReview/Mary_Major`) unless you include a wildcard (`*Mary_Major`). You can also specify the role name explicitly (`CodeCommitReview/Mary_Major`).
   + **Fully qualified ARN**: This option allows you to specify the fully qualified Amazon Resource Name (ARN) of the IAM user or role. This option also supports assumed roles used by other AWS services, such as AWS Lambda and AWS CodeBuild. For assumed roles, the ARN format should be `arn:aws:sts::AccountID:assumed-role/RoleName` for roles and `arn:aws:sts::AccountID:assumed-role/FunctionName` for functions.

   If you chose **IAM user name or assumed role** as the approver type, in **Value**, enter the name of the IAM user or role or the fully qualified ARN of the user or role. Choose **Add** again to add more users or roles, until you have added all the users or roles whose approvals count toward the number of required approvals. 

   Both approver types allow you to use wildcards (\$1) in their values. For example, if you choose the **IAM user name or assumed role** option, and you specify **CodeCommitReview/\$1**, all users who assume the role of **CodeCommitReview** are counted in the approval pool. Their individual role session names count toward the required number of approvers. In this way, both Mary\$1Major and Li\$1Juan are counted as approvals when signed in and assuming the role of `CodeCommitReview`. For more information about IAM ARNs, wildcards, and formats, see [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns).
**Note**  
Approval rules do not support cross-account approvals.

1. When you have finished configuring the approval rule, choose **Submit**.

 

## Create an approval rule for a pull request (AWS CLI)
<a name="how-to-create-pull-request-approval-rule-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

## To create an approval rule for a pull request in a CodeCommit repository

+ Run the **create-pull-request-approval-rule** command, specifying:
  + The ID of the pull request (with the **--id** option).
  + The name of the approval rule (with the **--approval-rule-name** option).
  + The content of the approval rule (with the **--approval-rule-content** option).

  When you create the approval rule, you can specify approvers in an approval pool in one of two ways:
  + **CodeCommitApprovers**: This option only requires an Amazon Web Services account and a resource. It can be used for both IAM users and federated access users whose name matches the provided resource name. This is a very powerful option that offers a great deal of flexibility. For example, if you specify the Amazon Web Services account 123456789012 and **Mary\$1Major**, all of the following are counted as approvals coming from that user:
    + An IAM user in the account (`arn:aws:iam::123456789012:user/Mary_Major`)
    + A federated user identified in IAM as Mary\$1Major (`arn:aws:sts::123456789012:federated-user/Mary_Major`)

    This option would not recognize an active session of someone assuming the role of **CodeCommitReview** with a role session name of Mary\$1Major (`arn:aws:sts::123456789012:assumed-role/CodeCommitReview/Mary_Major`) unless you include a wildcard (`*Mary_Major`).
  + **Fully qualified ARN**: This option allows you to specify the fully qualified Amazon Resource Name (ARN) of the IAM user or role. 

  For more information about IAM ARNs, wildcards, and formats, see [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns).

  The following example creates an approval rule named `Require two approved approvers` for a pull request with the ID of `27`. The rule specifies two approvals are required from an approval pool. The pool includes all users who access CodeCommit and assume the role of **CodeCommitReview** in the `123456789012` Amazon Web Services account. It also includes either an IAM user or federated user named `Nikhil_Jayashankar` in the same Amazon Web Services account:

  ```
  aws codecommit create-pull-request-approval-rule --pull-request-id 27 --approval-rule-name "Require two approved approvers" --approval-rule-content "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"CodeCommitApprovers:123456789012:Nikhil_Jayashankar\", \"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"
  ```

# View pull requests in an AWS CodeCommit repository
<a name="how-to-view-pull-request"></a>

You can use the AWS CodeCommit console or the AWS CLI to view pull requests for your repository. By default, you see only open pull requests, but you can change the filter to view all pull requests, only closed requests, only pull requests that you created, and more. 

**Topics**
+ [

## View pull requests (console)
](#how-to-view-pull-request-console)
+ [

## View pull requests (AWS CLI)
](#how-to-view-pull-request-cli)

## View pull requests (console)
<a name="how-to-view-pull-request-console"></a>

You can use the AWS CodeCommit console to view a list of pull requests in a CodeCommit repository. By changing the filter, you can change the list display to only show you a certain set of pull requests. For example, you can view a list of pull requests you created with a status of **Open**, or you can choose a different filter and view pull requests you created with a status of **Closed**.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to view pull requests. 

1. In the navigation pane, choose **Pull Requests**.

1. By default, a list of all open pull requests is displayed.   
![\[Pull requests displayed in the AWS CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view-list.png)

1. To change the display filter, choose from the list of available filters:
   + **Open pull requests** (default): Displays all pull requests with a status of **Open**.
   + **All pull requests**: Displays all pull requests.
   + **Closed pull requests**: Displays all pull requests with a status of **Closed**.
   + **My pull requests**: Displays all pull requests that you created, regardless of the status. It does not display reviews that you have commented on or otherwise participated in.
   + **My open pull requests**: Displays all pull requests that you created with a status of **Open**.
   + **My closed pull requests**: Displays all pull requests that you created with a status of **Closed**.

1. When you find a pull request in the displayed list that you would like to view, choose it.

## View pull requests (AWS CLI)
<a name="how-to-view-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

Follow these steps to use the AWS CLI to view pull requests in an CodeCommit repository.

1. To view a list of pull requests in a repository, run the **list-pull-requests** command, specifying:
   + The name of the CodeCommit repository where you want to view pull requests (with the **--repository-name** option).
   + (Optional) The status of the pull request (with the **--pull-request-status** option).
   + (Optional) The Amazon Resource Name (ARN) of the IAM user who created the pull request (with the **--author-arn** option).
   + (Optional) An enumeration token that can be used to return batches of results (with the **--next-token** option) 
   + (Optional) A limit on the number of returned results per request (with the **--max-results** option).

   For example, to list pull requests created by an IAM user with the ARN *arn:aws:iam::111111111111:user/Li\$1Juan* and the status of *CLOSED* in a CodeCommit repository named `MyDemoRepo`:

   ```
   aws codecommit list-pull-requests --author-arn arn:aws:iam::111111111111:user/Li_Juan --pull-request-status CLOSED --repository-name MyDemoRepo 
   ```

   If successful, this command produces output similar to the following:

   ```
   {
      "nextToken": "",
      "pullRequestIds": ["2","12","16","22","23","35","30","39","47"]
   }
   ```

   Pull request IDs are displayed in the order of most recent activity.

1. To view details of a pull request, run the **get-pull-request** command with the **--pull-request-id** option, specifying the ID of the pull request. For example, to view information about a pull request with the ID of *27*:

   ```
   aws codecommit get-pull-request --pull-request-id 27
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "pullRequest": {
           "approvalRules": [
               {
                   "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
                   "approvalRuleId": "dd8b17fe-EXAMPLE",
                   "approvalRuleName": "2-approver-rule-for-main",
                   "creationDate": 1571356106.936,
                   "lastModifiedDate": 571356106.936,
                   "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
                   "ruleContentSha256": "4711b576EXAMPLE"
               }
           ],
           "lastActivityDate": 1562619583.565,
           "pullRequestTargets": [
               {
                   "sourceCommit": "ca45e279EXAMPLE",
                   "sourceReference": "refs/heads/bugfix-1234",
                   "mergeBase": "a99f5ddbEXAMPLE",
                   "destinationReference": "refs/heads/main",
                   "mergeMetadata": {
                       "isMerged": false
                   },
                   "destinationCommit": "2abfc6beEXAMPLE",
                   "repositoryName": "MyDemoRepo"
               }
           ],
           "revisionId": "e47def21EXAMPLE",
           "title": "Quick fix for bug 1234",
           "authorArn": "arn:aws:iam::123456789012:user/Nikhil_Jayashankar",
           "clientRequestToken": "d8d7612e-EXAMPLE",
           "creationDate": 1562619583.565,
           "pullRequestId": "27",
           "pullRequestStatus": "OPEN"
       }
   }
   ```

1. <a name="get-pull-request-approval-state"></a>To view approvals on a pull request, run the **get-pull-request-approval-state** command, specifying:
   + The ID of the pull request (using the **--pull-request-id** option).
   + The revision ID of the pull request (using the **--revision-id option)**. You can get the current revision ID for a pull request by using the [get-pull-request](#get-pull-request) command.

   For example, to view approvals on a pull request with an ID of *8* and a revision ID of *9f29d167EXAMPLE*:

   ```
   aws codecommit get-pull-request-approval-state --pull-request-id 8 --revision-id 9f29d167EXAMPLE
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "approvals": [
           {
               "userArn": "arn:aws:iam::123456789012:user/Mary_Major",
               "approvalState": "APPROVE"
           }
       ]
   }
   ```

1. To view events in a pull request, run the **describe-pull-request-events** command with the **--pull-request-id** option, specifying the ID of the pull request. For example, to view the events for a pull request with the ID of *8*:

   ```
   aws codecommit describe-pull-request-events --pull-request-id 8
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "pullRequestEvents": [
           {
               "pullRequestId": "8",
               "pullRequestEventType": "PULL_REQUEST_CREATED",
               "eventDate": 1510341779.53,
               "actor": "arn:aws:iam::111111111111:user/Zhang_Wei"
           },
           {
               "pullRequestStatusChangedEventMetadata": {
                   "pullRequestStatus": "CLOSED"
               },
               "pullRequestId": "8",
               "pullRequestEventType": "PULL_REQUEST_STATUS_CHANGED",
               "eventDate": 1510341930.72,
               "actor": "arn:aws:iam::111111111111:user/Jane_Doe"
           }
       ]
   }
   ```

1. To view whether there are any merge conflicts for a pull request, run the **get-merge-conflicts** command, specifying:
   + The name of the CodeCommit repository (with the **--repository-name** option).
   + The branch, tag, HEAD, or other fully qualified reference for the source of the changes to use in the merge evaluation (with the **--source-commit-specifier** option).
   + The branch, tag, HEAD, or other fully qualified reference for the destination of the changes to use in the merge evaluation (with the **--destination-commit-specifier** option).
   + The merge option to use (with the **--merge-option** option) 

   For example, to view whether there are any merge conflicts between the tip of a source branch named *my-feature-branch* and a destination branch named *main* in a repository named `MyDemoRepo`:

   ```
   aws codecommit get-merge-conflicts --repository-name MyDemoRepo --source-commit-specifier my-feature-branch --destination-commit-specifier main --merge-option FAST_FORWARD_MERGE
   ```

   If successful, this command returns output similar to the following:

   ```
   {
       "destinationCommitId": "fac04518EXAMPLE",
       "mergeable": false,
       "sourceCommitId": "16d097f03EXAMPLE"
   }
   ```

# Review a pull request
<a name="how-to-review-pull-request"></a>

You can use the AWS CodeCommit console to review the changes included in a pull request. You can add comments to the request, files, and individual lines of code. You can also reply to comments made by other users. If your repository is [configured with notifications](how-to-repository-email.md), you receive emails when users reply to your comments or when users comment on a pull request.

You can use the AWS CLI to comment on a pull request and reply to comments. To review the changes, you must use the CodeCommit console, the **git diff** command, or a diff tool.

**Topics**
+ [

## Review a pull request (console)
](#how-to-review-pull-request-console)
+ [

## Review pull requests (AWS CLI)
](#how-to-review-pull-request-cli)

## Review a pull request (console)
<a name="how-to-review-pull-request-console"></a>

You can use the CodeCommit console to review a pull request in a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository. 

1. In the navigation pane, choose **Pull requests**.

1. By default, a list of all open pull requests is displayed. Choose the open pull request you want to review.   
![\[Open pull requests displayed in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view-list.png)
**Note**  
You can comment on a closed or merged pull request, but you cannot merge or reopen it.

1. In the pull request, choose **Changes**.

1. Do one of the following:
   + To add a general comment for the entire pull request, in **Comments on changes**, in **New comment**, enter a comment, and then choose **Save**. You can use [Markdown](https://docs.aws.amazon.com/general/latest/gr/aws-markdown.html), or you can enter your comment in plaintext.  
![\[A general comment on the changes in a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commenting-changecomment.png)
   + To add a comment to a file in the commit, in **Changes**, find the name of the file. Choose the comment icon ![\[The comment bubble icon that that indicates that you can leave a comment on that line of code.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commentbubble.png) that appears next to the file name, enter a comment, and then choose **Save**.   
![\[Adding a comment on a file in a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commenting-addfilecomment.png)
   + To add a comment to a changed line in the pull request, in **Changes**, go to the line you want to comment on. Choose the comment icon ![\[The comment bubble icon that that indicates that you can leave a comment on that line of code.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commentbubble.png) that appears for that line, enter a comment, and then choose **Save**.   
![\[Adding a comment on a line in a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-comment.png)

1. To reply to comments on a commit, in **Changes** or **Activity**, choose **Reply**. You can reply with text and with emojis.   
![\[Adding replies and emoji reactions to a comment.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commenting-commenttab.png)

   You can view the names of those who responded with a particular emoji reaction reply by choosing it. To view all emoji reactions and information about who responded with what emojis, choose **View all reactions**. If you've responded with an emoji to a comment, your response is shown in the icon for the emoji reaction button.
**Note**  
Reaction counts displayed in the console are accurate as of the time the page was loaded. For the most current information about emoji reaction counts, either refresh the page, or choose **View all reactions**.  
![\[Viewing information about users who responded to a comment with an emoji reaction.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-comment-view-reaction.png)

1. (Optional) To reply to a recommendation created by Amazon CodeGuru Reviewer, including providing feedback on the recommendation's quality, choose **Reply**. Use the reaction buttons to provide general information about whether you approve or disapprove the recommendation. Use the comment field to provide more details about your reaction.
**Note**  
Amazon CodeGuru Reviewer is an automated code review service that uses program analysis and machine learning to detect common issues and recommend fixes in your Java or Python code.  
You only see Amazon CodeGuru Reviewer comments if you have associated the repository with Amazon CodeGuru Reviewer, if the analysis is complete, and if the code in the pull request is Java or Python code. For more information, see [Amazon CodeGuru Reviewer and AWS CodeCommit](how-to-amazon-codeguru-reviewer.md).
Amazon CodeGuru Reviewer comments only appear in the **Changes** tab if the comments were made on the most recent revision of the pull request. They always appear in the **Activity** tab.
While you can respond with any of the available emoji reactions to Amazon CodeGuru Reviewer recommendations, only thumbs up and thumbs down emoji reactions are used to evaluate the usefulness of the recommendation.   
![\[A recommendation created by Amazon CodeGuru Reviewer with a review job in progress.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-reply-bot.png)

1. To approve the changes made in a pull request, choose **Approve**. 
**Note**  
You cannot approve a pull request that you created.

   You can view approvals, approval rules for a pull request, and approval rules created by approval rule templates in **Approvals**. If you decide you do not want to approve the pull request after all, you can choose **Revoke approval**.
**Note**  
You can only approve or revoke approval on an open pull request. You cannot approve or revoke approval on a pull request whose status is Merged or Closed.  
![\[Approvals and approval rules in a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-approval-rule-met.png)

## Review pull requests (AWS CLI)
<a name="how-to-review-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

You can review pull requests with the following AWS CLI commands:
+ [**post-comment-for-pull-request**](#post-comment-reply), to add a comment to a pull request
+ [**get-comments-for-pull-request**](#get-comments-for-pull-request), to view comments left on a pull request
+ [**update-pull-request-approval-state**](#update-pull-request-approval-state), to approve or revoke approval for a pull request
+ [**post-comment-reply**](#post-comment-reply), to reply to a comment in a pull request

You can also use emojis with comments in a pull request with the following commands: 
+ To reply to a comment with an emoji, run [**put-comment-reaction**](how-to-commit-comment.md#how-to-commit-comment-cli-commit-reply-emoji).
+ To view emoji reactions to a comment, run [**get-comment-reactions**](how-to-commit-comment.md#how-to-commit-comment-cli-commit-emoji-view).

**To use the AWS CLI to review pull requests in an CodeCommit repository**

1. To add a comment to a pull request in a repository, run the **post-comment-for-pull-request** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The name of the repository that contains the pull request (with the **--repository-name** option).
   + The full commit ID of the commit in the destination branch where the pull request is merged (with the **--before-commit-id** option).
   + The full commit ID of the commit in the source branch that is the current tip of the branch for the pull request when you post the comment (with the **--after-commit-id** option).
   + A unique, client-generated idempotency token (with the **--client-request-token** option).
   + The content of your comment (with the **--content** option).
   + A list of location information about where to place the comment, including:
     + The name of the file being compared, including its extension and subdirectory, if any (with the **filePath** attribute).
     + The line number of the change in a compared file (with the **filePosition** attribute).
     + Whether the comment on the change is "before" or "after" in the comparison between the source and destination branches (with the **relativeFileVersion** attribute).

   For example, use this command to add the comment *"These don't appear to be used anywhere. Can we remove them?"* on the change to the *ahs\$1count.py* file in a pull request with the ID of *47* in a repository named *MyDemoRepo*.

   ```
   aws codecommit post-comment-for-pull-request --pull-request-id "47" --repository-name MyDemoRepo --before-commit-id 317f8570EXAMPLE --after-commit-id 5d036259EXAMPLE --client-request-token 123Example --content "These don't appear to be used anywhere. Can we remove them?" --location filePath=ahs_count.py,filePosition=367,relativeFileVersion=AFTER   
   ```

   If successful, this command produces output similar to the following.

   ```
   { 
            "afterBlobId": "1f330709EXAMPLE",
            "afterCommitId": "5d036259EXAMPLE",
            "beforeBlobId": "80906a4cEXAMPLE",
            "beforeCommitId": "317f8570EXAMPLE",
            "comment": {
                  "authorArn": "arn:aws:iam::111111111111:user/Saanvi_Sarkar",
                  "clientRequestToken": "123Example",
                  "commentId": "abcd1234EXAMPLEb5678efgh",
                  "content": "These don't appear to be used anywhere. Can we remove them?",
                  "creationDate": 1508369622.123,
                  "deleted": false,
                  "lastModifiedDate": 1508369622.123,
                  "callerReactions": [],
                  "reactionCounts": []
               }
                "location": { 
                  "filePath": "ahs_count.py",
                  "filePosition": 367,
                  "relativeFileVersion": "AFTER"
                },
            "repositoryName": "MyDemoRepo",
            "pullRequestId": "47"
    }
   ```

1. To view comments for a pull request, run the **get-comments-for-pull-request** command, specifying:
   + The name of the CodeCommit repository (with the `--repository-name` option).
   + The system-generated ID of the pull request (with the `--pull-request-id` option).
   + (Optional) An enumeration token to return the next batch of the results (with the `--next-token` option).
   + (Optional) A non-negative integer to limit the number of returned results (with the `--max-results` option).

   For example, use this command to view comments for a pull request with an ID of 42.

   ```
   aws codecommit get-comments-for-pull-request --pull-request-id 42
   ```

   If successful, this command produces output similar to the following.

   ```
   {
      "commentsForPullRequestData": [ 
         { 
            "afterBlobId": "1f330709EXAMPLE",
            "afterCommitId": "5d036259EXAMPLE",
            "beforeBlobId": "80906a4cEXAMPLE",
            "beforeCommitId": "317f8570EXAMPLE",
            "comments": [ 
               { 
                  "authorArn": "arn:aws:iam::111111111111:user/Saanvi_Sarkar",
                  "clientRequestToken": "",
                  "commentId": "abcd1234EXAMPLEb5678efgh",
                  "content": "These don't appear to be used anywhere. Can we remove them?",
                  "creationDate": 1508369622.123,
                  "deleted": false,
                  "lastModifiedDate": 1508369622.123,
                  "callerReactions": [],
                  "reactionCounts": 
                   {
                     "THUMBSUP" : 6,
                     "CONFUSED" : 1
                   }
               },
               {
                  "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
                  "clientRequestToken": "",
                  "commentId": "442b498bEXAMPLE5756813",
                  "content": "Good catch. I'll remove them.",
                  "creationDate": 1508369829.104,
                  "deleted": false,
                  "lastModifiedDate": 150836912.273,
                  "callerReactions": ["THUMBSUP"]
                  "reactionCounts": 
                   {
                     "THUMBSUP" : 14
                   }
                }
            ],
            "location": { 
               "filePath": "ahs_count.py",
               "filePosition": 367,
               "relativeFileVersion": "AFTER"
            },
            "repositoryName": "MyDemoRepo",
            "pullRequestId": "42"
         }
      ],
      "nextToken": "exampleToken"
   }
   ```

1. <a name="update-pull-request-approval-state"></a>To approve or revoke approval for a pull request, run the **update-pull-request-approval-state** command, specifying:
   + The ID of the pull request (using the **--pull-request-id** option).
   + The revision ID of the pull request (using the **--revision-id option)**. You can get the current revision ID for a pull request by using the [get-pull-request](how-to-view-pull-request.md#get-pull-request) command.
   + The approval state you want to apply (using the **--approval-state**) option. Valid approval states include `APPROVE` and `REVOKE`.

   For example, use this command to approve a pull request with the ID of *27* and a revision ID of *9f29d167EXAMPLE*.

   ```
   aws codecommit update-pull-request-approval-state --pull-request-id 27 --revision-id 9f29d167EXAMPLE --approval-state "APPROVE"
   ```

   If successful, this command returns nothing.

1. To post a reply to a comment in a pull request, run the **post-comment-reply** command, specifying:
   + The system-generated ID of the comment to which you want to reply (with the **--in-reply-to** option).
   + A unique, client-generated idempotency token (with the **--client-request-token** option).
   + The content of your reply (with the **--content** option). 

    For example, use this command to add the reply *"Good catch. I'll remove them."* to the comment with the system-generated ID of *abcd1234EXAMPLEb5678efgh*. 

   ```
   aws codecommit post-comment-reply --in-reply-to abcd1234EXAMPLEb5678efgh --content "Good catch. I'll remove them." --client-request-token 123Example
   ```

   If successful, this command produces output similar to the following.

   ```
   { 
       "comment": {
           "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
           "clientRequestToken": "123Example",
           "commentId": "442b498bEXAMPLE5756813",
           "content": "Good catch. I'll remove them.",
           "creationDate": 1508369829.136,
           "deleted": false,
           "lastModifiedDate": 150836912.221,
           "callerReactions": [],
           "reactionCounts": []
       }
    }
   ```

# Update a pull request
<a name="how-to-update-pull-request"></a>

You can update a pull request with further code changes by pushing commits to the source branch of an open pull request. For more information, see [Create a commit in AWS CodeCommit](how-to-create-commit.md).

You can use the AWS CodeCommit console or the AWS CLI to update the title or description of a pull request. You might want to update the pull request title or description because:
+ Other users don't understand the description, or the original title is misleading.
+ You want the title or description to reflect changes made to the source branch of an open pull request.

## Update a pull request (console)
<a name="how-to-update-pull-request-console"></a>

You can use the CodeCommit console to update the title and description of a pull request in an CodeCommit repository. To update the code in the pull request, push commits to the source branch of an open pull request.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to update a pull request. 

1. In the navigation pane, choose **Pull requests**.

1. By default, a list of all open pull requests is displayed. Choose the open pull request you want to update.

1. In the pull request, choose **Details**, and then choose **Edit details** to edit the title or description.
**Note**  
You cannot update the title or description of a closed or merged pull request.

## Update pull requests (AWS CLI)
<a name="how-to-update-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

You might also be interested in the following commands:
+ **[update-pull-request-approval-state](how-to-review-pull-request.md#update-pull-request-approval-state)**, to approve or revoke approval on a pull request.
+ [**create-pull-request-approval-rule**](how-to-create-pull-request-approval-rule.md#how-to-create-pull-request-approval-rule-cli), to create an approval rule for a pull request.
+ [**delete-pull-request-approval-rule**](how-to-edit-delete-pull-request-approval-rule.md#delete-pull-request-approval-rule), to delete an approval rule for a pull request.
+ [Create a commit using the AWS CLI](how-to-create-commit.md#how-to-create-commit-cli) or [Create a commit using a Git client](how-to-create-commit.md#how-to-create-commit-git), to create and push additional code changes to the source branch of an open pull request.

**To use the AWS CLI to update pull requests in a CodeCommit repository**

1.  To update the title of a pull request in a repository, run the **update-pull-request-title** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The title of the pull request (with the **--title** option).

   For example, to update the title of a pull request with the ID of *47*:

   ```
   aws codecommit update-pull-request-title --pull-request-id 47 --title "Consolidation of global variables - updated review"  
   ```

1. To update the description of a pull request, run the **update-pull-request-description** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The description (with the **--description** option). 

    For example, to update the description of a pull request with the ID of *47* :

   ```
   aws codecommit update-pull-request-description --pull-request-id 47 --description "Updated the pull request to remove unused global variable."
   ```

# Edit or delete an approval rule for a pull request
<a name="how-to-edit-delete-pull-request-approval-rule"></a>

When you have an approval rule on a pull request, you cannot merge that pull request until its conditions have been met. You can change the approval rules for pull requests to make it easier to satisfy their conditions, or to increase the rigor of reviews. You can change the number of users who must approve a pull request. You can also add, remove, or change the membership in an approval pool of users for the rule. Lastly, if you no longer want to use an approval rule for a pull request, you can delete it.

**Note**  
You can also override approval rules for a pull request. For more information, see [Override approval rules on a pull request](how-to-override-approval-rules.md).

You can use the AWS CodeCommit console or the AWS CLI to edit and delete approval rules for your repository. 

**Topics**
+ [

## Edit or delete an approval rule for a pull request (console)
](#how-to-edit-delete-pull-request-approval-rule-console)
+ [

## Edit or delete an approval rule for a pull request (AWS CLI)
](#how-to-edit-delete-pull-request-approval-rule-cli)

## Edit or delete an approval rule for a pull request (console)
<a name="how-to-edit-delete-pull-request-approval-rule-console"></a>

You can use the CodeCommit console to edit or delete an approval rule for a pull request in a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository where you want to edit or delete an approval rule for a pull request. 

1. In the navigation pane, choose **Pull Requests**.

1. Choose the pull request where you want to edit or delete an approval rule. You can only edit and delete approval rules for open pull requests.  
![\[A list of pull requests for a repository in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view.png)

1. In the pull request, choose **Approvals**, and then choose the rule you want to edit or delete from the list. Do one of the following:
   + If you want to edit the rule, choose **Edit**. 
   + If you want to delete the rule, choose **Delete**, and then follow the instructions for verifying the deletion of the rule.

1. In **Edit approval rule**, make the changes you want to the rule, and then choose **Submit**.  
![\[Editing an approval rule\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-edit-rule.png)

1. When you have finished configuring the approval rule, choose **Submit**.

 

## Edit or delete an approval rule for a pull request (AWS CLI)
<a name="how-to-edit-delete-pull-request-approval-rule-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

You can use the AWS CLI to edit the content of an approval rule and to delete an approval rule. 

**Note**  
You might also be interested in the following commands:  
**[update-pull-request-approval-state](how-to-review-pull-request.md#update-pull-request-approval-state)**, to approve or revoke approval on a pull request.
[**get-pull-request-approval-states**](how-to-view-pull-request.md#get-pull-request-approval-state), to view the approvals on the pull request.
[**evaluate-pull-request-approval-rules**](how-to-merge-pull-request.md#evaluate-pull-request-approval-rules), to determine whether approval rules for a pull request have had their conditions satisifed.

**To use the AWS CLI to edit or delete an approval rule for a pull request in a CodeCommit repository**<a name="update-pull-request-approval-rule-content"></a>

1. To edit an approval rule, run the **update-pull-request-approval-rule-content** command, specifying:
   + The ID of the pull request (with the **--id** option).
   + The name of the approval rule (with the **--approval-rule-name** option).
   + The content of the approval rule (with the **--approval-rule-content** option).

   This example updates an approval rule named *Require two approved approvers* for a pull request with the ID of *27*. The rule requires one user approval from an approval pool that includes any IAM user in the *123456789012* Amazon Web Services account:

   ```
   aws codecommit update-pull-request-approval-rule-content --pull-request-id 27 --approval-rule-name "Require two approved approvers" --approval-rule-content "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}"
   ```

1. <a name="delete-pull-request-approval-rule"></a>To delete an approval rule, run the **delete-pull-request-approval-rule** command, specifying:
   + The ID of the pull request (with the **--id** option).
   + The name of the approval rule (with the **--approval-rule-name** option).

   For example, to delete an approval rule with the name *My Approval Rule* for a pull request with the ID of *15*:

   ```
   aws codecommit delete-pull-request-approval-rule --pull-request-id 15 --approval-rule-name "My Approval Rule"
   ```

# Override approval rules on a pull request
<a name="how-to-override-approval-rules"></a>

In the normal course of development, you want users to meet the conditions of approval rules before you merge pull requests. However, there might be times when you need to expedite merging a pull request. For example, you might want to put a bug fix into production, but no one in the approval pool is available to approve the pull request. In cases like these, you can choose to override the approval rules on a pull request. You can override all approval rules for a pull request, including those created specifically for the pull request and generated from an approval rule template. You cannot selectively override a specific approval rule, just all rules. After you have set aside the approval rule requirements by overriding the rules, you can merge the pull request to its destination branch.

When you override approval rules on a pull request, information about the user who overrode the rules is recorded in the activity for the pull request. This way you can go back into the history of a pull request and review who overrode the rules. You can also choose to revoke the override if the pull request is still open. After the pull request has been merged, you can no longer revoke the override.

**Topics**
+ [

## Override approval rules (console)
](#how-to-override-approval-rules-console)
+ [

## Override approval rules (AWS CLI)
](#how-to-override-approval-rules-cli)

## Override approval rules (console)
<a name="how-to-override-approval-rules-console"></a>

You can override the requirements of approval rules on a pull request in the console, as part of reviewing a pull request. If you change your mind, you can revoke your override, and the approval rule requirements are reapplied. You can only override approval rules or revoke an override if the pull request is still open. If it is merged or closed, you cannot change its override state.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository. 

1. In the navigation pane, choose **Pull requests**. Choose the pull request where you want to override approval rule requirements, or revoke an override.

1. On the **Approvals** tab, choose **Override approval rules**. The requirements are set aside, and the button text changes to **Revoke override**. To reapply the approval rule requirements, choose **Revoke override**.

## Override approval rules (AWS CLI)
<a name="how-to-override-approval-rules-cli"></a>

You can use the AWS CLI to override approval rule requirements. You can also use it to view the override status for a pull request.<a name="override-approval-rules"></a>

## To override approval rule requirements on a pull request
<a name="override-approval-rules"></a>

1. At a terminal or command line, run the **override-pull-request-approval-rules** command, specifying:
   + The system-generated ID of the pull request.
   + The latest revision ID of the pull request. To view this information, use **get-pull-request**.
   + The status you want for the override, `OVERRIDE` or `REVOKE`. The `REVOKE` status removes the `OVERRIDE` status but is not saved.

   For example, to override approval rules on a pull request with an ID of **34** and a revision ID of **927df8d8EXAMPLE**:

   ```
   aws codecommit override-pull-request-approval-rules --pull-request-id 34 --revision-id 927df8d8dEXAMPLE --override-status OVERRIDE
   ```

1. If successful, this command returns nothing.

1. To revoke the override on a pull request with an ID of **34** and a revision ID of **927df8d8EXAMPLE**:

   ```
   aws codecommit override-pull-request-approval-rules --pull-request-id 34 --revision-id 927df8d8dEXAMPLE --override-status REVOKE
   ```<a name="get-override-status"></a>

## To get information about the override status of a pull request
<a name="get-override-status"></a>

1. At a terminal or command line, run the **get-pull-request-override-state** command, specifying:
   + The system-generated ID of the pull request.
   + The latest revision ID of the pull request. To view this information, use **get-pull-request**.

   For example, to view the override state for a pull request with an ID of **34** and a revision ID of **927df8d8EXAMPLE**:

   ```
   aws codecommit get-pull-request-override-state --pull-request-id 34 --revision-id 927df8d8dEXAMPLE
   ```

1. If successful, this command produces output similar to the following:

   ```
   {
       "overridden": true,
       "overrider": "arn:aws:iam::123456789012:user/Mary_Major"
   }
   ```

# Merge a pull request in an AWS CodeCommit repository
<a name="how-to-merge-pull-request"></a>

After your code has been reviewed and all approval rules (if any) on the pull request have been satisfied, you can merge a pull request in one of several ways:
+ <a name="is-mergable"></a>You can use the console to merge your source branch to the destination branch using one of the available merge strategies, which also closes the pull request. You can also resolve any merge conflicts in the console. The console displays a message that indicates if the pull request is mergeable or if conflicts must be resolved. When all conflicts are resolved and you choose **Merge**, the merge is performed using the merge strategy that you choose. Fast-forward is the default merge strategy, which is the default option for Git. Depending on the state of the code in the source and destination branches, that strategy might not be available, but other options might be, such as squash or 3-way.
+ You can use the AWS CLI to merge and close the pull request using the fast-forward, squash, or 3-way merge strategy. 
+ <a name="why-git-merge"></a>On your local computer, you can use the **git merge** command to merge the source branch into the destination branch, and then push your merged code to the destination branch. This approach has drawbacks that you should carefully consider. It merges the pull request regardless if the requirements for approval rules on the pull request have been satisfied, circumventing those controls. Merging and pushing the destination branch also closes the pull request automatically if the pull request is merged using the fast-forward merge strategy. One advantage of this approach is that the **git merge** command allows you to choose merge options or strategies that are not available in the CodeCommit console. For more information about **git merge** and merge options, see [git-merge](https://git-scm.com/docs/git-merge) or your Git documentation.

CodeCommit closes a pull request automatically if either the source or destination branch of the pull request is deleted.

**Topics**
+ [

## Merge a pull request (console)
](#how-to-merge-pull-request-console)
+ [

## Merge a pull request (AWS CLI)
](#how-to-merge-pull-request-cli)

## Merge a pull request (console)
<a name="how-to-merge-pull-request-console"></a>

You can use the CodeCommit console to merge a pull request in a CodeCommit repository. After the status of a pull request is changed to **Merged**, it no longer appears in the list of open pull requests. A merged pull request is categorized as closed. It cannot be changed back to **Open**, but users can still comment on the changes and reply to comments. After a pull request is merged or closed, you cannot approve it, revoke approval for it, or override the approval rules applied to the pull request.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository. 

1. In the navigation pane, choose **Pull requests**.

1. By default, a list of all open pull requests is displayed. Choose the open pull request you want to merge.

1. In the pull request, choose **Approvals**. Review the list of approvers, and verify that all approval rules (if any) have had their conditions satisfied. You cannot merge a pull request if one or more approval rules have the status of **Rule not satisfied**. If no one has approved the pull request, consider whether you want to merge it, or whether you want to wait for approvals.
**Note**  
If an approval rule was created for a pull request, you can edit it or delete it to unblock the merge. If the approval rule was created with an approval rule template, you cannot edit or delete it. You can only choose to override the requirements. For more information, see [Override approval rules on a pull request](how-to-override-approval-rules.md).  
![\[A pull request showing an approval rule whose condititions have not been satisfied and an empty list of approvers.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-approval-rule-not-met.png)

1. Choose **Merge**.

1. In the pull request, choose between the available merge strategies. Merge strategies that cannot be applied appear greyed out. If no merge strategies are available, you can choose to manually resolve conflicts in the CodeCommit console, or you can resolve them locally using your Git client. For more information, see [Resolve conflicts in a pull request in an AWS CodeCommit repository](how-to-resolve-conflict-pull-request.md).  
![\[A pull request showing the merge strategies available for the merge in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-merge-squash.png)
   + A fast-forward merge moves the reference for the destination branch forward to the most recent commit of the source branch. This is the default behavior of Git when possible. No merge commit is created, but all commit history from the source branch is retained as if it had occurred in the destination branch. Fast-forward merges do not appear as a branch merge in the commit visualizer view of the destination branch's history because no merge commit is created. The tip of the source branch is fast-forwarded to the tip of the destination branch. 
   + A squash merge creates one commit that contains the changes in the source branch and applies that single squashed commit to the destination branch. By default, the commit message for that squash commit contains all the commit messages of the changes in the source branch. No individual commit history of the branch changes is retained. This can help simplify your repository history while still retaining a graphical representation of the merge in the commit visualizer view of the destination branch's history. 
   + A three-way merge creates a merge commit for the merge in the destination branch, but also retains the individual commits made in the source branch as part of the history of the destination branch. This can help maintain a complete history of changes to your repository.

1. If you choose the squash or 3-way merge strategy, review the automatically generated commit message and modify it if you want to change the information. Add your name and email address for the commit history.

1. (Optional) Clear the option to delete the source branch as part of the merge. The default is to delete the source branch when a pull request is merged.

1. Choose **Merge pull request** to complete the merge.

## Merge a pull request (AWS CLI)
<a name="how-to-merge-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

**To use the AWS CLI to merge pull requests in a CodeCommit repository**

1. <a name="evaluate-pull-request-approval-rules"></a>To evaluate whether a pull request has had all of its approval rules satisfied and is ready to be merged, run the **evaluate-pull-request-approval-rules** command, specifying:
   + The ID of the pull request (using the **--pull-request-id** option).
   + The revision ID of the pull request (using the **--revision-id option)**. You can get the current revision ID for a pull request by using the **[get-pull-request](how-to-view-pull-request.md#get-pull-request)** command.

   For example, to evaluate the state of approval rules on a pull request with an ID of *27* and a revision ID of *9f29d167EXAMPLE*:

   ```
   aws codecommit evaluate-pull-request-approval-rules --pull-request-id 27 --revision-id 9f29d167EXAMPLE
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "evaluation": {
           "approved": false,
           "approvalRulesNotSatisfied": [
               "Require two approved approvers"
           ],
           "overridden": false,
           "approvalRulesSatisfied": []
       }
   }
   ```
**Note**  
This output indicates that a pull request is not mergable because the requirements of an approval rule have not been satisfied. To merge this pull request, you can have reviewers approve it to meet the conditions of the rule. Depending on your permissions and how the rule was created, you might also be able to edit, override, or delete the rule. For more information, see [Review a pull request](how-to-review-pull-request.md), [Override approval rules on a pull request](how-to-override-approval-rules.md), and [Edit or delete an approval rule for a pull request](how-to-edit-delete-pull-request-approval-rule.md). 

1. To merge and close a pull request using the fast-forward merge strategy, run the **merge-pull-request-by-fast-forward** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The full commit ID of the tip of the source branch (with the **--source-commit-id** option). 
   + The name of the repository (with the **--repository-name** option).

    For example, to merge and close a pull request with the ID of *47* and a source commit ID of *99132ab0EXAMPLE* in a repository named *MyDemoRepo*:

   ```
   aws codecommit merge-pull-request-by-fast-forward --pull-request-id 47 --source-commit-id 99132ab0EXAMPLE --repository-name MyDemoRepo
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "pullRequest": {
           "approvalRules": [
               {
                   "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
                   "approvalRuleId": "dd8b17fe-EXAMPLE",
                   "approvalRuleName": "I want one approver for this pull request",
                   "creationDate": 1571356106.936,
                   "lastModifiedDate": 571356106.936,
                   "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
                   "ruleContentSha256": "4711b576EXAMPLE"
               }
           ],
           "authorArn": "arn:aws:iam::123456789012:user/Li_Juan",
           "clientRequestToken": "",
           "creationDate": 1508530823.142,
           "description": "Review the latest changes and updates to the global variables",
           "lastActivityDate": 1508887223.155,
           "pullRequestId": "47",
           "pullRequestStatus": "CLOSED",
           "pullRequestTargets": [
               {
                   "destinationCommit": "9f31c968EXAMPLE",
                   "destinationReference": "refs/heads/main",
                   "mergeMetadata": {
                       "isMerged": true,
                       "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major"
                   },
                   "repositoryName": "MyDemoRepo",
                   "sourceCommit": "99132ab0EXAMPLE",
                   "sourceReference": "refs/heads/variables-branch"
               }
           ],
           "title": "Consolidation of global variables"
       }
   }
   ```

1. To merge and close a pull request using the squash merge strategy, run the **merge-pull-request-by-squash** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The full commit ID of the tip of the source branch (with the **--source-commit-id** option). 
   + The name of the repository (with the **--repository-name** option).
   + The level of conflict detail you want to use (with the **--conflict-detail-level** option). If unspecified, the default **`FILE_LEVEL`** is used.
   + The conflict resolution strategy you want to use (with the **--conflict-resolution-strategy** option). If unspecified, this defaults to `NONE`, and conflicts must be resolved manually.
   + The commit message to include (with the **--commit-message** option).
   + The name to use for the commit (with the **--author-name** option).
   + The email address to use for the commit (with the **--email** option).
   + Whether to keep any empty folders (with the **--keep-empty-folders** option).

   The following example merges and closes a pull request with the ID of *47* and a source commit ID of *99132ab0EXAMPLE* in a repository named *MyDemoRepo*. It uses the conflict detail of `LINE_LEVEL` and the conflict resolution strategy of `ACCEPT_SOURCE`:

   ```
   aws codecommit merge-pull-request-by-squash --pull-request-id 47 --source-commit-id 99132ab0EXAMPLE --repository-name MyDemoRepo --conflict-detail-level LINE_LEVEL --conflict-resolution-strategy ACCEPT_SOURCE --author-name "Jorge Souza" --email "jorge_souza@example.com" --commit-message "Merging pull request 47 by squash and accepting source in merge conflicts"
   ```

   If successful, this command produces the same kind of output as merging by fast-forward, output similar to the following:

   ```
   {
       "pullRequest": {
           "approvalRules": [
               {
                   "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
                   "approvalRuleId": "dd8b17fe-EXAMPLE",
                   "approvalRuleName": "2-approver-rule-for-main",
                   "creationDate": 1571356106.936,
                   "lastModifiedDate": 571356106.936,
                   "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
                   "originApprovalRuleTemplate": {
                       "approvalRuleTemplateId": "dd8b17fe-EXAMPLE",
                       "approvalRuleTemplateName": "2-approver-rule-for-main"
                   },
                   "ruleContentSha256": "4711b576EXAMPLE"
               }
           ],
           "authorArn": "arn:aws:iam::123456789012:user/Li_Juan",
           "clientRequestToken": "",
           "creationDate": 1508530823.142,
           "description": "Review the latest changes and updates to the global variables",
           "lastActivityDate": 1508887223.155,
           "pullRequestId": "47",
           "pullRequestStatus": "CLOSED",
           "pullRequestTargets": [
               {
                   "destinationCommit": "9f31c968EXAMPLE",
                   "destinationReference": "refs/heads/main",
                   "mergeMetadata": {
                       "isMerged": true,
                       "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major"
                   },
                   "repositoryName": "MyDemoRepo",
                   "sourceCommit": "99132ab0EXAMPLE",
                   "sourceReference": "refs/heads/variables-branch"
               }
           ],
           "title": "Consolidation of global variables"
       }
   }
   ```

1. To merge and close a pull request using the three-way merge strategy, run the **merge-pull-request-by-three-way** command, specifying:
   + The ID of the pull request (with the **--pull-request-id** option).
   + The full commit ID of the tip of the source branch (with the **--source-commit-id** option). 
   + The name of the repository (with the **--repository-name** option).
   + The level of conflict detail you want to use (with the **--conflict-detail-level** option). If unspecified, the default **`FILE_LEVEL`** is used.
   + The conflict resolution strategy you want to use (with the **--conflict-resolution-strategy** option). If unspecified, this defaults to `NONE`, and conflicts must be resolved manually.
   + The commit message to include (with the **--commit-message** option).
   + The name to use for the commit (with the **--author-name** option).
   + The email address to use for the commit (with the **--email** option).
   + Whether to keep any empty folders (with the **--keep-empty-folders** option).

   The following example merges and closes a pull request with the ID of *47* and a source commit ID of *99132ab0EXAMPLE* in a repository named *MyDemoRepo*. It uses the default options for conflict detail and conflict resolution strategy:

   ```
   aws codecommit merge-pull-request-by-three-way --pull-request-id 47 --source-commit-id 99132ab0EXAMPLE --repository-name MyDemoRepo --author-name "Maria Garcia" --email "maria_garcia@example.com" --commit-message "Merging pull request 47 by three-way with default options"
   ```

   If successful, this command produces the same kind of output as merging by fast-forward, similar to the following:

   ```
   {
       "pullRequest": {
           "approvalRules": [
               {
                   "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
                   "approvalRuleId": "dd8b17fe-EXAMPLE",
                   "approvalRuleName": "2-approver-rule-for-main",
                   "creationDate": 1571356106.936,
                   "lastModifiedDate": 571356106.936,
                   "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
                   "originApprovalRuleTemplate": {
                       "approvalRuleTemplateId": "dd8b17fe-EXAMPLE",
                       "approvalRuleTemplateName": "2-approver-rule-for-main"
                   },
                   "ruleContentSha256": "4711b576EXAMPLE"
               }
           ],
           "authorArn": "arn:aws:iam::123456789012:user/Li_Juan",
           "clientRequestToken": "",
           "creationDate": 1508530823.142,
           "description": "Review the latest changes and updates to the global variables",
           "lastActivityDate": 1508887223.155,
           "pullRequestId": "47",
           "pullRequestStatus": "CLOSED",
           "pullRequestTargets": [
               {
                   "destinationCommit": "9f31c968EXAMPLE",
                   "destinationReference": "refs/heads/main",
                   "mergeMetadata": {
                       "isMerged": true,
                       "mergedBy": "arn:aws:iam::123456789012:user/Mary_Major"
                   },
                   "repositoryName": "MyDemoRepo",
                   "sourceCommit": "99132ab0EXAMPLE",
                   "sourceReference": "refs/heads/variables-branch"
               }
           ],
           "title": "Consolidation of global variables"
       }
   }
   ```

# Resolve conflicts in a pull request in an AWS CodeCommit repository
<a name="how-to-resolve-conflict-pull-request"></a>

If your pull request has conflicts and cannot be merged, you can try to resolve the conflicts in one of several ways:
+ On your local computer, you can use the **git diff** command to find the conflicts between the two branches and make changes to resolve them. You can also use a difference tool or other software to help you find and resolve differences. Once you have resolved them to your satisfaction, you can push your source branch with the changes that contain the resolved conflicts, which updates the pull request. For more information about **git diff** and **git difftool**, see your Git documentation.
+ In the console, you can choose **Resolve conflicts**. This opens a plain-text editor that shows conflicts in a similar way as the **git diff** command. You can manually review the conflicts in each file that contain them, make changes, and then update the pull request with your changes.
+ In the AWS CLI, you can use the AWS CLI to get information about merge conflicts and create an unreferenced merge commit to test a merge. 

**Topics**
+ [

## Resolve conflicts in a pull request (console)
](#how-to-resolve-conflict-pull-request-console)
+ [

## Resolve conflicts in a pull request (AWS CLI)
](#how-to-resolve-conflict-pull-request-cli)

## Resolve conflicts in a pull request (console)
<a name="how-to-resolve-conflict-pull-request-console"></a>

You can use the CodeCommit console to resolve conflicts in a pull request in a CodeCommit repository. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository. 

1. In the navigation pane, choose **Pull requests**.

1. By default, a list of all open pull requests is displayed. Choose the open pull request that you want to merge but it contains conflicts.

1. In the pull request, choose **Resolve conflicts**. This option only appears if there are conflicts that must be resolved before the pull request can be merged.  
![\[A pull request showing that it has conflicts that must be resolved before it can be merged.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-resolve-conflicts.png)

1. A conflict resolution window opens listing each file that has conflicts that must be resolved. Choose each file in the list to review the conflicts, and make any necessary changes until all conflicts have been resolved.  
![\[The conflict resolution editor showing a file with conflicts that have not yet been resolved.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-resolve.png)
   + You can choose to use the source file contents, the destination file contents, or if the file is not a binary file, to manually edit the contents of a file so it contains only the changes you want. Standard git diff markers are used to show the conflicts between the destination (HEAD) and source branches in the file.
   + If a file is a binary file, a Git submodule, or if there is a file/folder name conflict, you must choose to use the source file or the destination file to resolve the conflicts. You cannot view or edit binary files in the CodeCommit console.
   + If there are file mode conflicts, you see the option to resolve that conflict by choosing between the file mode of the source file and the file mode of the destination file. 
   + If you decide you want to discard your changes for a file and restore it to its conflicted state, choose **Reset file**. This allows you to resolve the conflicts in a different way.

1. When you are satisfied with your changes, choose **Update pull request**.
**Note**  
You must resolve all conflicts in all files before you can successfully update the pull request with your changes. 

1. The pull request is updated with your changes and mergeable. You see the merge page. You can choose to merge the pull request at this time, or you can return to the list of pull requests. 

## Resolve conflicts in a pull request (AWS CLI)
<a name="how-to-resolve-conflict-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

No single AWS CLI command enables you to resolve conflicts in a pull request and merge that request. However, you can use individual commands to discover conflicts, attempt to resolve them, and test whether a pull request is mergeable. You can use:
+ **get-merge-options**, to find out what merge options are available for a merge between two commit specifiers.
+ **get-merge-conflicts**, to return a list of files with merge conflicts in a merge between two commit specifiers.
+ **batch-describe-merge-conflicts**, to get information about all merge conflicts in files in a merge between two commits using a specified merge strategy. 
+ **describe-merge-conflicts**, to get detailed information about merge conflicts for a specific file between two commits using a specified merge strategy.
+ **create-unreferenced-merge-commit**, to test the result of merging two commit specifiers using a specified merge strategy.

1. <a name="get-merge-options"></a>To discover what merge options are available for a merge between two commit specifiers, run the **get-merge-options** command, specifying:
   + A commit specifier for the source of the merge (with the **--source-commit-specifier** option).
   + A commit specifier for the destination for the merge (with the **--destination-commit-specifier** option). 
   + The name of the repository (with the **--repository-name** option).
   + (Optional) A conflict resolution strategy to use (with the **--conflict-resolution-strategy** option).
   + (Optional) The level of detail you want about any conflicts (with the **--conflict-detail-level** option).

    For example, to determine the merge strategies available for merging a source branch named *bugfix-1234* with a destination branch named *main* in a repository named *MyDemoRepo*:

   ```
   aws codecommit get-merge-options --source-commit-specifier bugfix-1234 --destination-commit-specifier main --repository-name MyDemoRepo
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "mergeOptions": [
           "FAST_FORWARD_MERGE",
           "SQUASH_MERGE",
           "THREE_WAY_MERGE"
       ],
       "sourceCommitId": "d49940adEXAMPLE",
       "destinationCommitId": "86958e0aEXAMPLE",
       "baseCommitId": "86958e0aEXAMPLE"
   }
   ```

1. <a name="get-merge-conflict"></a>To get a list of files that contain merge conflicts in a merge between two commit specifiers, run the **get-merge-conflicts** command, specifying:
   + A commit specifier for the source of the merge (with the **--source-commit-specifier** option).
   + A commit specifier for the destination for the merge (with the **--destination-commit-specifier** option). 
   + The name of the repository (with the **--repository-name** option).
   + The merge option you want to use (with the **--merge-option** option).
   + (Optional) The level of detail you want about any conflicts (with the **--conflict-detail-level** option).
   + (Optional) A conflict resolution strategy to use (with the **--conflict-resolution-strategy** option).
   + (Optional) The maximum number of files with conflicts to return (with the **--max-conflict-files** option).

   For example, to get a list of files that contain conflicts in a merge between a source branch named feature-randomizationfeature and a destination branch named main using the three-way merge strategy in a repository named MyDemoRepo:

   ```
   aws codecommit get-merge-conflicts --source-commit-specifier feature-randomizationfeature --destination-commit-specifier main --merge-option THREE_WAY_MERGE --repository-name MyDemoRepo
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "mergeable": false,
       "destinationCommitId": "86958e0aEXAMPLE",
       "sourceCommitId": "6ccd57fdEXAMPLE",
       "baseCommitId": "767b6958EXAMPLE",
       "conflictMetadataList": [
           {
               "filePath": "readme.md",
               "fileSizes": {
                   "source": 139,
                   "destination": 230,
                   "base": 85
               },
               "fileModes": {
                   "source": "NORMAL",
                   "destination": "NORMAL",
                   "base": "NORMAL"
               },
               "objectTypes": {
                   "source": "FILE",
                   "destination": "FILE",
                   "base": "FILE"
               },
               "numberOfConflicts": 1,
               "isBinaryFile": {
                   "source": false,
                   "destination": false,
                   "base": false
               },
               "contentConflict": true,
               "fileModeConflict": false,
               "objectTypeConflict": false,
               "mergeOperations": {
                   "source": "M",
                   "destination": "M"
               }
           }
       ]
   }
   ```

1. <a name="batch-describe-merge-conflicts"></a>To get information about merge conflicts in all files or a subset of files in a merge between two commit specifiers, run the **batch-describe-merge-conflicts** command, specifying:
   + A commit specifier for the source of the merge (with the **--source-commit-specifier** option).
   + A commit specifier for the destination for the merge (with the **--destination-commit-specifier** option). 
   + The merge option you want to use (with the **--merge-option** option).
   + The name of the repository (with the **--repository-name** option).
   + (Optional) A conflict resolution strategy to use (with the **--conflict-resolution-strategy** option).
   + (Optional) The level of detail you want about any conflicts (with the **--conflict-detail-level** option).
   + (Optional) The maximum number of merge hunks to return (with the **--max-merge-hunks** option).
   + (Optional) The maximum number of files with conflicts to return (with the **--max-conflict-files** option).
   + (Optional) The path of target files to use to describe the conflicts (with the **--file-paths** option).

    For example, to determine the merge conflicts for merging a source branch named *feature-randomizationfeature* with a destination branch named *main* using the *THREE\$1WAY\$1MERGE* strategy in a repository named *MyDemoRepo*:

   ```
   aws codecommit batch-describe-merge-conflicts --source-commit-specifier feature-randomizationfeature --destination-commit-specifier main --merge-option THREE_WAY_MERGE --repository-name MyDemoRepo
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "conflicts": [
           {
               "conflictMetadata": {
                   "filePath": "readme.md",
                   "fileSizes": {
                       "source": 139,
                       "destination": 230,
                       "base": 85
                   },
                   "fileModes": {
                       "source": "NORMAL",
                       "destination": "NORMAL",
                       "base": "NORMAL"
                   },
                   "objectTypes": {
                       "source": "FILE",
                       "destination": "FILE",
                       "base": "FILE"
                   },
                   "numberOfConflicts": 1,
                   "isBinaryFile": {
                       "source": false,
                       "destination": false,
                       "base": false
                   },
                   "contentConflict": true,
                   "fileModeConflict": false,
                   "objectTypeConflict": false,
                   "mergeOperations": {
                       "source": "M",
                       "destination": "M"
                   }
               },
               "mergeHunks": [
                   {
                       "isConflict": true,
                       "source": {
                           "startLine": 0,
                           "endLine": 3,
                           "hunkContent": "VGhpcyBpEXAMPLE=="
                       },
                       "destination": {
                           "startLine": 0,
                           "endLine": 1,
                           "hunkContent": "VXNlIHRoEXAMPLE="
                       }
                   }
               ]
           }
       ],
       "errors": [],
       "destinationCommitId": "86958e0aEXAMPLE",
       "sourceCommitId": "6ccd57fdEXAMPLE",
       "baseCommitId": "767b6958EXAMPLE"
   }
   ```

1. <a name="describe-merge-conflicts"></a>To get detailed information about any merge conflicts for a specific file in a merge between two commit specifiers, run the **describe-merge-conflicts** command, specifying:
   + A commit specifier for the source of the merge (with the **--source-commit-specifier** option).
   + A commit specifier for the destination for the merge (with the **--destination-commit-specifier** option). 
   + The merge option you want to use (with the **--merge-option** option).
   + The path of target file to use to describe the conflicts (with the **--file-path** option).
   + The name of the repository (with the **--repository-name** option).
   + (Optional) A conflict resolution strategy to use (with the **--conflict-resolution-strategy** option).
   + (Optional) The level of detail you want about any conflicts (with the **--conflict-detail-level** option).
   + (Optional) The maximum number of merge hunks to return (with the **--max-merge-hunks** option).
   + (Optional) The maximum number of files with conflicts to return (with the **--max-conflict-files** option).

   For example, to determine the merge conflicts for a file named *readme.md* in a source branch named *feature-randomizationfeature* with a destination branch named *main* using the *THREE\$1WAY\$1MERGE* strategy in a repository named *MyDemoRepo*:

   ```
   aws codecommit describe-merge-conflicts --source-commit-specifier feature-randomizationfeature --destination-commit-specifier main --merge-option THREE_WAY_MERGE --file-path readme.md --repository-name MyDemoRepo
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "conflictMetadata": {
           "filePath": "readme.md",
           "fileSizes": {
               "source": 139,
               "destination": 230,
               "base": 85
           },
           "fileModes": {
               "source": "NORMAL",
               "destination": "NORMAL",
               "base": "NORMAL"
           },
           "objectTypes": {
               "source": "FILE",
               "destination": "FILE",
               "base": "FILE"
           },
           "numberOfConflicts": 1,
           "isBinaryFile": {
               "source": false,
               "destination": false,
               "base": false
           },
           "contentConflict": true,
           "fileModeConflict": false,
           "objectTypeConflict": false,
           "mergeOperations": {
               "source": "M",
               "destination": "M"
           }
       },
       "mergeHunks": [
           {
               "isConflict": true,
               "source": {
                   "startLine": 0,
                   "endLine": 3,
                   "hunkContent": "VGhpcyBpEXAMPLE=="
               },
               "destination": {
                   "startLine": 0,
                   "endLine": 1,
                   "hunkContent": "VXNlIHRoEXAMPLE="
               }
           }
       ],
       "destinationCommitId": "86958e0aEXAMPLE",
       "sourceCommitId": "6ccd57fdEXAMPLE",
       "baseCommitId": "767b69580EXAMPLE"
   }
   ```

1. <a name="create-unreferenced-merge-commit"></a>To create an unreferenced commit that represents the result of merging two commit specifiers, run the **create-unreferenced-merge-commit** command, specifying:
   + A commit specifier for the source of the merge (with the **--source-commit-specifier** option).
   + A commit specifier for the destination for the merge (with the **--destination-commit-specifier** option). 
   + The merge option you want to use (with the **--merge-option** option).
   + The name of the repository (with the **--repository-name** option).
   + (Optional) A conflict resolution strategy to use (with the **--conflict-resolution-strategy** option).
   + (Optional) The level of detail you want about any conflicts (with the **--conflict-detail-level** option).
   + (Optional) The commit message to include (with the **--commit-message** option).
   + (Optional) The name to use for the commit (with the **--name** option).
   + (Optional) The email address to use for the commit (with the **--email** option).
   + (Optional) Whether to keep any empty folders (with the **--keep-empty-folders** option).

    For example, to determine the merge conflicts for merging a source branch named *bugfix-1234* with a destination branch named *main* using the ACCEPT\$1SOURCE strategy in a repository named *MyDemoRepo*:

   ```
   aws codecommit create-unreferenced-merge-commit --source-commit-specifier bugfix-1234 --destination-commit-specifier main --merge-option THREE_WAY_MERGE --repository-name MyDemoRepo --name "Maria Garcia" --email "maria_garcia@example.com" --commit-message "Testing the results of this merge."
   ```

   If successful, this command produces output similar to the following:

   ```
   {
       "commitId": "4f178133EXAMPLE",
       "treeId": "389765daEXAMPLE"
   }
   ```

# Close a pull request in an AWS CodeCommit repository
<a name="how-to-close-pull-request"></a>

If you want to close a pull request without merging the code, you can do so in one of several ways:
+ In the console, you can close a pull request without merging the code. You might want to do this if you want to use the **git merge** command to merge the branches manually, or if the code in the pull request source branch isn't code you want merged into the destination branch. 
+ You can delete the source branch specified in the pull request. CodeCommit closes a pull request automatically if either the source or destination branch of the pull request is deleted.
+ In the AWS CLI, you can update the status of a pull request from `OPEN` to `CLOSED`. This closes the pull request without merging the code. 

**Topics**
+ [

## Close a pull request (console)
](#how-to-close-pull-request-console)
+ [

## Close a pull request (AWS CLI)
](#how-to-close-pull-request-cli)

## Close a pull request (console)
<a name="how-to-close-pull-request-console"></a>

You can use the CodeCommit console to close a pull request in a CodeCommit repository. After the status of a pull request is changed to **Closed**, it cannot be changed back to **Open**, but users can still comment on the changes and reply to comments.

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the name of the repository. 

1. In the navigation pane, choose **Pull requests**.

1. By default, a list of all open pull requests is displayed. Choose the open pull request you want to close.  
![\[Pull requests displayed in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view.png)

1. In the pull request, choose **Close pull request**. This option closes the pull request without attempting to merge the source branch into the destination branch. This option does not provide a way to delete the source branch as part of closing the pull request, but you can do it yourself after the request is closed.

## Close a pull request (AWS CLI)
<a name="how-to-close-pull-request-cli"></a>

To use AWS CLI commands with CodeCommit, install the AWS CLI. For more information, see [Command line reference](cmd-ref.md). 

**To use the AWS CLI to close pull requests in a CodeCommit repository**
+ To update the status of a pull request in a repository from `OPEN` to `CLOSED`, run the **update-pull-request-status** command, specifying:
  + The ID of the pull request (with the **--pull-request-id** option).
  + The status of the pull request (with the **--pull-request-status** option).

  For example, to update the status of a pull request with the ID of *42* to a status of *CLOSED* in a CodeCommit repository named `MyDemoRepo`:

  ```
  aws codecommit update-pull-request-status --pull-request-id 42 --pull-request-status CLOSED  
  ```

  If successful, this command produces output similar to the following:

------
#### [ JSON ]

****  

  ```
  {
      "Version":"2012-10-17",		 	 	 
      "Statement": [
          {
              "Effect": "Allow",
              "Action": "codecommit:GetRepository",
              "Resource": [
                  "arn:aws:codecommit:us-east-2:111122223333:MySharedDemoRepo"
              ]
          }
      ]
  }
  ```

------