

# 使用 AWS CLI 的 CodeCommit 示例
<a name="cli_codecommit_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 CodeCommit 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `associate-approval-rule-template-with-repository`
<a name="codecommit_AssociateApprovalRuleTemplateWithRepository_cli_topic"></a>

以下代码示例演示了如何使用 `associate-approval-rule-template-with-repository`。

**AWS CLI**  
**将审批规则模板与存储库关联**  
以下 `associate-approval-rule-template-with-repository` 示例将指定的审批规则模板与名为 `MyDemoRepo` 的存储库关联。  

```
aws codecommit associate-approval-rule-template-with-repository \
    --repository-name MyDemoRepo  \
    --approval-rule-template-name 2-approver-rule-for-main
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[将审批规则模板与存储库关联](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-associate-template.html#associate-template-repository)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AssociateApprovalRuleTemplateWithRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/associate-approval-rule-template-with-repository.html)。

### `batch-associate-approval-rule-template-with-repositories`
<a name="codecommit_BatchAssociateApprovalRuleTemplateWithRepositories_cli_topic"></a>

以下代码示例演示了如何使用 `batch-associate-approval-rule-template-with-repositories`。

**AWS CLI**  
**在单个操作中将一个审批规则模板与多个存储库关联**  
以下 `batch-associate-approval-rule-template-with-repositories` 示例将指定的审批规则模板与名为 `MyDemoRepo` 和 `MyOtherDemoRepo` 的存储库关联。  
请注意：审批规则模板特定于创建模板时所处的 AWS 区域。它们只能与该 AWS 区域的存储库关联。  

```
aws codecommit batch-associate-approval-rule-template-with-repositories \
    --repository-names MyDemoRepo, MyOtherDemoRepo  \
    --approval-rule-template-name 2-approver-rule-for-main
```
输出：  

```
{
    "associatedRepositoryNames": [
        "MyDemoRepo",
        "MyOtherDemoRepo"
    ],
    "errors": []
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[将审批规则模板与存储库关联](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-associate-template.html#batch-associate-template-repositories)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchAssociateApprovalRuleTemplateWithRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-associate-approval-rule-template-with-repositories.html)。

### `batch-describe-merge-conflicts`
<a name="codecommit_BatchDescribeMergeConflicts_cli_topic"></a>

以下代码示例演示了如何使用 `batch-describe-merge-conflicts`。

**AWS CLI**  
**获取有关在两个提交说明符之间的合并中所有文件或部分文件合并冲突的信息**  
以下 `batch-describe-merge-conflicts` 示例确定在名为 `MyDemoRepo` 的存储库中合并名为 `feature-randomizationfeature` 的源分支与使用 `THREE_WAY_MERGE` 策略的名为 `main` 的目标分支合并时产生的合并冲突。  

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

```
{
    "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"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解决拉取请求中的冲突](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-resolve-conflict-pull-request.html#batch-describe-merge-conflicts)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchDescribeMergeConflicts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-describe-merge-conflicts.html)。

### `batch-disassociate-approval-rule-template-from-repositories`
<a name="codecommit_BatchDisassociateApprovalRuleTemplateFromRepositories_cli_topic"></a>

以下代码示例演示了如何使用 `batch-disassociate-approval-rule-template-from-repositories`。

**AWS CLI**  
**在单个操作中解除审批规则模板与多个存储库的关联**  
以下 `batch-disassociate-approval-rule-template-from-repositories` 示例解除指定的审批规则模板与名为 `MyDemoRepo` 和 `MyOtherDemoRepo` 的存储库关联。  

```
aws codecommit batch-disassociate-approval-rule-template-from-repositories \
    --repository-names MyDemoRepo, MyOtherDemoRepo  \
    --approval-rule-template-name 1-approval-rule-for-all pull requests
```
输出：  

```
{
    "disassociatedRepositoryNames": [
        "MyDemoRepo",
        "MyOtherDemoRepo"
    ],
    "errors": []
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解除审批规则模板的关联](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-disassociate-template.html#batch-disassociate-template)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchDisassociateApprovalRuleTemplateFromRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-disassociate-approval-rule-template-from-repositories.html)。

### `batch-get-commits`
<a name="codecommit_BatchGetCommits_cli_topic"></a>

以下代码示例演示了如何使用 `batch-get-commits`。

**AWS CLI**  
**查看有关多个提交的信息**  
以下 `batch-get-commits` 示例显示指定提交的详细信息。  

```
aws codecommit batch-get-commits  \
    --repository-name MyDemoRepo  \
    --commit-ids 317f8570EXAMPLE 4c925148EXAMPLE
```
输出：  

```
{
    "commits": [
      {
        "additionalData": "",
        "committer": {
            "date": "1508280564 -0800",
            "name": "Mary Major",
            "email": "mary_major@example.com"
        },
        "author": {
            "date": "1508280564 -0800",
            "name": "Mary Major",
            "email": "mary_major@example.com"
        },
        "commitId": "317f8570EXAMPLE",
        "treeId": "1f330709EXAMPLE",
        "parents": [
            "6e147360EXAMPLE"
        ],
        "message": "Change variable name and add new response element"
    },
    {
        "additionalData": "",
        "committer": {
            "date": "1508280542 -0800",
            "name": "Li Juan",
            "email": "li_juan@example.com"
        },
        "author": {
            "date": "1508280542 -0800",
            "name": "Li Juan",
            "email": "li_juan@example.com"
        },
        "commitId": "4c925148EXAMPLE",
        "treeId": "1f330709EXAMPLE",
        "parents": [
            "317f8570EXAMPLE"
        ],
        "message": "Added new class"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[查看提交的详细信息](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-view-commit-details.html#how-to-view-commit-details-cli-batch-get-commits)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchGetCommits](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-get-commits.html)。

### `batch-get-repositories`
<a name="codecommit_BatchGetRepositories_cli_topic"></a>

以下代码示例演示了如何使用 `batch-get-repositories`。

**AWS CLI**  
**查看有关多个存储库的详细信息**  
此示例显示了有关多个 AWS CodeCommit 存储库的详细信息。  

```
aws codecommit batch-get-repositories \
    --repository-names MyDemoRepo MyOtherDemoRepo
```
输出：  

```
{
    "repositoriesNotFound": [],
    "repositories": [
         {
            "creationDate": 1429203623.625,
            "defaultBranch": "main",
            "repositoryName": "MyDemoRepo",
            "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo",
            "lastModifiedDate": 1430783812.0869999,
            "repositoryDescription": "My demonstration repository",
            "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo",
            "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
            "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo"
            "accountId": "111111111111"
        },
        {
            "creationDate": 1429203623.627,
            "defaultBranch": "main",
            "repositoryName": "MyOtherDemoRepo",
            "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo",
            "lastModifiedDate": 1430783812.0889999,
            "repositoryDescription": "My other demonstration repository",
            "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo",
            "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE",
            "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyOtherDemoRepo"
            "accountId": "111111111111"
        }
    ],
    "repositoriesNotFound": []
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchGetRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-get-repositories.html)。

### `create-approval-rule-template`
<a name="codecommit_CreateApprovalRuleTemplate_cli_topic"></a>

以下代码示例演示了如何使用 `create-approval-rule-template`。

**AWS CLI**  
**创建审批规则模板**  
以下 `create-approval-rule-template` 示例创建一个名为 `2-approver-rule-for-main ``. The template requires two users who assume the role of ``CodeCommitReview` 的审批规则模板，用于批准任何拉取请求，然后再将其合并到 `main` 分支。  

```
aws codecommit create-approval-rule-template \
    --approval-rule-template-name 2-approver-rule-for-main \
    --approval-rule-template-description  "Requires two developers from the team to approve the pull request if the destination branch is main" \
    --approval-rule-template-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"
```
输出：  

```
{
    "approvalRuleTemplate": {
        "approvalRuleTemplateName": "2-approver-rule-for-main",
        "creationDate": 1571356106.936,
        "approvalRuleTemplateId": "dd8b17fe-EXAMPLE",
        "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
        "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
        "approvalRuleTemplateDescription": "Requires two developers from the team to approve the pull request if the destination branch is main",
        "lastModifiedDate": 1571356106.936,
        "ruleContentSha256": "4711b576EXAMPLE"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[创建审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-create-template.html#create-template-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateApprovalRuleTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-approval-rule-template.html)。

### `create-branch`
<a name="codecommit_CreateBranch_cli_topic"></a>

以下代码示例演示了如何使用 `create-branch`。

**AWS CLI**  
**创建分支**  
此示例在 AWS CodeCommit 存储库中创建了一个分支。该命令只在出现错误时生成输出。  
命令:  

```
aws codecommit create-branch --repository-name MyDemoRepo --branch-name MyNewBranch --commit-id 317f8570EXAMPLE
```
输出：  

```
None.
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-branch.html)。

### `create-commit`
<a name="codecommit_CreateCommit_cli_topic"></a>

以下代码示例演示了如何使用 `create-commit`。

**AWS CLI**  
**创建提交**  
以下 `create-commit` 示例演示了如何为存储库创建初始提交，以便将 `readme.md` 文件添加到 `main` 分支中名为 `MyDemoRepo` 的存储库。  

```
aws codecommit create-commit \
    --repository-name MyDemoRepo \
    --branch-name main \
    --put-files "filePath=readme.md,fileContent='Welcome to our team repository.'"
```
输出：  

```
{
    "filesAdded": [
        {
            "blobId": "5e1c309d-EXAMPLE",
            "absolutePath": "readme.md",
            "fileMode": "NORMAL"
        }
    ],
    "commitId": "4df8b524-EXAMPLE",
    "treeId": "55b57003-EXAMPLE",
    "filesDeleted": [],
    "filesUpdated": []
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[在 AWS CodeCommit 中创建提交](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-create-commit.html#how-to-create-commit-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-commit.html)。

### `create-pull-request-approval-rule`
<a name="codecommit_CreatePullRequestApprovalRule_cli_topic"></a>

以下代码示例演示了如何使用 `create-pull-request-approval-rule`。

**AWS CLI**  
**创建拉取请求的审批规则**  
以下 `create-pull-request-approval-rule` 示例为指定拉取请求创建名为 `Require two approved approvers` 的审批规则。该规则指定审批池中需要存在两个审批。池中包括通过在 `123456789012` AWS 账户中代入 `CodeCommitReview` 角色来访问 CodeCommit 的所有用户。还包括同一 AWS 账户中的 IAM 用户或名为 `Nikhil_Jayashankar` 的联合用户。  

```
aws codecommit create-pull-request-approval-rule  \
    --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/*\"]}]}"
```
输出：  

```
{
    "approvalRule": {
        "approvalRuleName": "Require two approved approvers",
        "lastModifiedDate": 1570752871.932,
        "ruleContentSha256": "7c44e6ebEXAMPLE",
        "creationDate": 1570752871.932,
        "approvalRuleId": "aac33506-EXAMPLE",
        "approvalRuleContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"CodeCommitApprovers:123456789012:Nikhil_Jayashankar\", \"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
        "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[创建审批规则](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-create-pull-request-approval-rule.html#how-to-create-pull-request-approval-rule-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreatePullRequestApprovalRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-pull-request-approval-rule.html)。

### `create-pull-request`
<a name="codecommit_CreatePullRequest_cli_topic"></a>

以下代码示例演示了如何使用 `create-pull-request`。

**AWS CLI**  
**创建拉取请求**  
以下 `create-pull-request` 示例创建一个名为“发音难度分析器”的拉取请求，其描述为“请在周二之前查看这些更改”，目标是“jane-branch”源分支，并将合并到名为“MyDemoRepo”的 AWS CodeCommit 存储库中的默认分支“main”中。  

```
aws codecommit create-pull-request \
    --title "My Pull Request" \
    --description "Please review these changes by Tuesday" \
    --client-request-token 123Example \
    --targets repositoryName=MyDemoRepo,sourceReference=MyNewBranch
```
输出：  

```
{
    "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": "dd3d22fe-EXAMPLE",
                    "approvalRuleTemplateName": "2-approver-rule-for-main"
                },
                "ruleContentSha256": "4711b576EXAMPLE"
            }
        ],
        "authorArn": "arn:aws:iam::111111111111:user/Jane_Doe",
        "description": "Please review these changes by Tuesday",
        "title": "Pronunciation difficulty analyzer",
        "pullRequestTargets": [
            {
                "destinationCommit": "5d036259EXAMPLE",
                "destinationReference": "refs/heads/main",
                "repositoryName": "MyDemoRepo",
                "sourceCommit": "317f8570EXAMPLE",
                "sourceReference": "refs/heads/jane-branch",
                "mergeMetadata": {
                    "isMerged": false
                }
            }
        ],
        "lastActivityDate": 1508962823.285,
        "pullRequestId": "42",
        "clientRequestToken": "123Example",
        "pullRequestStatus": "OPEN",
        "creationDate": 1508962823.285
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreatePullRequest](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-pull-request.html)。

### `create-repository`
<a name="codecommit_CreateRepository_cli_topic"></a>

以下代码示例演示了如何使用 `create-repository`。

**AWS CLI**  
**创建存储库** ()  
此示例创建一个存储库并将其与用户的 AWS 帐户相关联。  
命令:  

```
aws codecommit create-repository --repository-name MyDemoRepo --repository-description "My demonstration repository"
```
输出：  

```
{
    "repositoryMetadata": {
        "repositoryName": "MyDemoRepo",
                "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
                "lastModifiedDate": 1444766838.027,
        "repositoryDescription": "My demonstration repository",
                "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
        "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
                "Arn": "arn:aws:codecommit:us-east-1:111111111111EXAMPLE:MyDemoRepo",
        "accountId": "111111111111"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-repository.html)。

### `create-unreferenced-merge-commit`
<a name="codecommit_CreateUnreferencedMergeCommit_cli_topic"></a>

以下代码示例演示了如何使用 `create-unreferenced-merge-commit`。

**AWS CLI**  
**创建表示两个提交说明符的合并结果的未引用提交**  
以下 `create-unreferenced-merge-commit` 示例创建一个提交，表示在名为 `MyDemoRepo` 的存储库中，使用 THREE\$1WAY\$1MERGE 策略在名为 `bugfix-1234` 的源分支与名为 `main` 的目标分支之间的合并结果。  

```
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."
```
输出：  

```
{
    "commitId": "4f178133EXAMPLE",
    "treeId": "389765daEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解决拉取请求中的冲突](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-resolve-conflict-pull-request.html#batch-describe-merge-conflicts)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateUnreferencedMergeCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-unreferenced-merge-commit.html)。

### `credential-helper`
<a name="codecommit_CredentialHelper_cli_topic"></a>

以下代码示例演示了如何使用 `credential-helper`。

**AWS CLI**  
**使用 AWS CodeCommit 设置 AWS CLI 中包含的凭证助手**  
此 `credential-helper` 实用程序没有设计为直接从 AWS CLI 调用。相反，它旨在用作设置本地计算机的 `git config` 命令的参数。每当 Git 需要通过向 AWS 进行身份验证来与 CodeCommit 存储库进行交互时，它都允许 Git 使用 HTTPS 和 IAM 用户凭证或 Amazon EC2 实例角色的加密签名版本。  

```
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
```
输出：  

```
[credential]
    helper = !aws codecommit credential-helper $@
    UseHttpPath = true
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的“使用其他方法设置 AWS CodeCommit”。仔细阅读内容，然后按照以下主题之一中的步骤操作：《AWS CodeCommit 用户指南》**中的“在 Linux、macOS 或 Unix 上建立 HTTPS 连接”或“在 Windows 上建立 HTTPS 连接”。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CredentialHelper](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/credential-helper.html)。

### `delete-approval-rule-template`
<a name="codecommit_DeleteApprovalRuleTemplate_cli_topic"></a>

以下代码示例演示了如何使用 `delete-approval-rule-template`。

**AWS CLI**  
**删除审批规则模板**  
以下 `delete-approval-rule-template` 示例删除指定审批规则模板。  

```
aws codecommit delete-approval-rule-template  \
    --approval-rule-template-name 1-approver-for-all-pull-requests
```
输出：  

```
{
    "approvalRuleTemplateId": "41de97b7-EXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[删除审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-delete-template.html#delete-template)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteApprovalRuleTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-approval-rule-template.html)。

### `delete-branch`
<a name="codecommit_DeleteBranch_cli_topic"></a>

以下代码示例演示了如何使用 `delete-branch`。

**AWS CLI**  
**删除分支**  
此示例说明如何删除 AWS CodeCommit 存储库中的分支。  
命令:  

```
aws codecommit delete-branch --repository-name MyDemoRepo --branch-name MyNewBranch
```
输出：  

```
{
  "branch": {
      "commitId": "317f8570EXAMPLE",
      "branchName": "MyNewBranch"
  }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-branch.html)。

### `delete-comment-content`
<a name="codecommit_DeleteCommentContent_cli_topic"></a>

以下代码示例演示了如何使用 `delete-comment-content`。

**AWS CLI**  
**删除评论的内容**  
如果您创建了评论，则只能删除该评论的内容。此示例演示如何删除系统生成的 ID 为 `ff30b348EXAMPLEb9aa670f` 的评论内容。  

```
aws codecommit delete-comment-content \
    --comment-id ff30b348EXAMPLEb9aa670f
```
输出：  

```
{
    "comment": {
        "creationDate": 1508369768.142,
        "deleted": true,
        "lastModifiedDate": 1508369842.278,
        "clientRequestToken": "123Example",
        "commentId": "ff30b348EXAMPLEb9aa670f",
        "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
        "callerReactions": [],
        "reactionCounts":
        {
            "CLAP" : 1
        }
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteCommentContent](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-comment-content.html)。

### `delete-file`
<a name="codecommit_DeleteFile_cli_topic"></a>

以下代码示例演示了如何使用 `delete-file`。

**AWS CLI**  
**删除文件**  
以下 `delete-file` 示例演示如何在名为 `MyDemoRepo` 的存储库中删除名为 `main` 的分支中名为 `README.md` 的文件，该分支的最新提交 ID 为 `c5709475EXAMPLE`。  

```
aws codecommit delete-file \
    --repository-name MyDemoRepo \
    --branch-name main \
    --file-path README.md \
    --parent-commit-id c5709475EXAMPLE
```
输出：  

```
{
    "blobId":"559b44fEXAMPLE",
    "commitId":"353cf655EXAMPLE",
    "filePath":"README.md",
    "treeId":"6bc824cEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit API 参考指南》**中的[在 AWS CodeCommit 中编辑或删除文件](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-edit-file.html?shortFooter=true#how-to-edit-file-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteFile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-file.html)。

### `delete-pull-request-approval-rule`
<a name="codecommit_DeletePullRequestApprovalRule_cli_topic"></a>

以下代码示例演示了如何使用 `delete-pull-request-approval-rule`。

**AWS CLI**  
**删除拉取请求的审批规则**  
以下 `delete-pull-request-approval-rule` 示例删除指定拉取请求的名为 `My Approval Rule` 的审批规则。  

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

```
{
    "approvalRuleId": "077d8e8a8-EXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[编辑或删除审批规则](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-edit-delete-pull-request-approval-rule.html#delete-pull-request-approval-rule)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeletePullRequestApprovalRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-pull-request-approval-rule.html)。

### `delete-repository`
<a name="codecommit_DeleteRepository_cli_topic"></a>

以下代码示例演示了如何使用 `delete-repository`。

**AWS CLI**  
**删除存储库**（）  
此示例说明如何删除 AWS CodeCommit 存储库。  
命令:  

```
aws codecommit delete-repository --repository-name MyDemoRepo
```
输出：  

```
{
  "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-repository.html)。

### `describe-merge-conflicts`
<a name="codecommit_DescribeMergeConflicts_cli_topic"></a>

以下代码示例演示了如何使用 `describe-merge-conflicts`。

**AWS CLI**  
**获取有关合并冲突的详细信息**  
以下 `describe-merge-conflicts` 示例使用 THREE\$1WAY\$1MERGE 策略确定指定源分支和目标分支中名为 `readme.md` 的文件的合并冲突。  

```
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
```
输出：  

```
{
    "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"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解决拉取请求中的冲突](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-resolve-conflict-pull-request.html#describe-merge-conflicts)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeMergeConflicts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/describe-merge-conflicts.html)。

### `describe-pull-request-events`
<a name="codecommit_DescribePullRequestEvents_cli_topic"></a>

以下代码示例演示了如何使用 `describe-pull-request-events`。

**AWS CLI**  
**查看拉取请求中的事件**  
以下 `describe-pull-request-events` 示例检索 ID 为“8”的拉取请求的事件。  

```
aws codecommit describe-pull-request-events --pull-request-id 8
```
输出：  

```
{
    "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"
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribePullRequestEvents](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/describe-pull-request-events.html)。

### `disassociate-approval-rule-template-from-repository`
<a name="codecommit_DisassociateApprovalRuleTemplateFromRepository_cli_topic"></a>

以下代码示例演示了如何使用 `disassociate-approval-rule-template-from-repository`。

**AWS CLI**  
**解除审批规则模板与存储库的关联**  
以下 `disassociate-approval-rule-template-from-repository` 示例解除指定的审批规则模板与名为 `MyDemoRepo` 的存储库的关联。  

```
aws codecommit disassociate-approval-rule-template-from-repository \
    --repository-name MyDemoRepo  \
    --approval-rule-template-name 1-approver-rule-for-all-pull-requests
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解除审批规则模板的关联](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-disassociate-template.html#disassociate-template)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DisassociateApprovalRuleTemplateFromRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/disassociate-approval-rule-template-from-repository.html)。

### `evaluate-pull-request-approval-rules`
<a name="codecommit_EvaluatePullRequestApprovalRules_cli_topic"></a>

以下代码示例演示了如何使用 `evaluate-pull-request-approval-rules`。

**AWS CLI**  
**评估拉取请求是否满足其所有审批规则**  
以下 `evaluate-pull-request-approval-rules` 示例评估指定拉取请求的审批规则的状态。在此示例中，拉取请求未满足审批规则，因此命令输出显示 `approved` 值为 `false`。  

```
aws codecommit evaluate-pull-request-approval-rules \
    --pull-request-id 27  \
    --revision-id 9f29d167EXAMPLE
```
输出：  

```
{
    "evaluation": {
        "approved": false,
        "approvalRulesNotSatisfied": [
            "Require two approved approvers"
        ],
        "overridden": false,
        "approvalRulesSatisfied": []
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[合并拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-merge-pull-request.html#evaluate-pull-request-approval-rules)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [EvaluatePullRequestApprovalRules](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/evaluate-pull-request-approval-rules.html)。

### `get-approval-rule-template`
<a name="codecommit_GetApprovalRuleTemplate_cli_topic"></a>

以下代码示例演示了如何使用 `get-approval-rule-template`。

**AWS CLI**  
**获取审批规则模板的内容**  
以下 `get-approval-rule-template` 示例获取名为 `1-approver-rule-for-all-pull-requests` 的审批规则模板的内容。  

```
aws codecommit get-approval-rule-template \
    --approval-rule-template-name 1-approver-rule-for-all-pull-requests
```
输出：  

```
{
    "approvalRuleTemplate": {
        "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
        "ruleContentSha256": "621181bbEXAMPLE",
        "lastModifiedDate": 1571356106.936,
        "creationDate": 1571356106.936,
        "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
        "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan",
        "approvalRuleTemplateId": "a29abb15-EXAMPLE",
        "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team."
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#get-template)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetApprovalRuleTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-approval-rule-template.html)。

### `get-blob`
<a name="codecommit_GetBlob_cli_topic"></a>

以下代码示例演示了如何使用 `get-blob`。

**AWS CLI**  
**查看有关 Git blob 对象的信息**  
以下 `get-blob` 示例检索名为“MyDemoRepo”的 AWS CodeCommit 存储库中 ID 为“2eb4af3bEXAMPLE”的 Git blob 的相关信息。  

```
aws codecommit get-blob  --repository-name MyDemoRepo  --blob-id 2eb4af3bEXAMPLE
```
输出：  

```
{
    "content": "QSBCaW5hcnkgTGFyToEXAMPLE="
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetBlob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-blob.html)。

### `get-branch`
<a name="codecommit_GetBranch_cli_topic"></a>

以下代码示例演示了如何使用 `get-branch`。

**AWS CLI**  
**查看有关分支的信息**  
此示例获取有关 AWS CodeCommit 存储库中分支的信息。  
命令:  

```
aws codecommit get-branch --repository-name MyDemoRepo --branch-name MyNewBranch
```
输出：  

```
{
  "BranchInfo": {
        "commitID": "317f8570EXAMPLE",
                "branchName": "MyNewBranch"
  }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-branch.html)。

### `get-comment-reactions`
<a name="codecommit_GetCommentReactions_cli_topic"></a>

以下代码示例演示了如何使用 `get-comment-reactions`。

**AWS CLI**  
**查看对评论的表情符号反应**  
以下 `get-comment-reactions` 示例列出对 ID 为 `abcd1234EXAMPLEb5678efgh` 的评论的所有表情符号反应。如果您的 shell 的字体支持显示表情符号版本 1.0，则会在 `emoji` 输出中显示表情符号。  

```
aws codecommit get-comment-reactions \
    --comment-id abcd1234EXAMPLEb5678efgh
```
输出：  

```
{
    "reactionsForComment": {
        [
           {
               "reaction": {
                    "emoji:"??",
                    "shortCode": "thumbsup",
                    "unicode": "U+1F44D"
                },
                "users": [
                    "arn:aws:iam::123456789012:user/Li_Juan",
                    "arn:aws:iam::123456789012:user/Mary_Major",
                    "arn:aws:iam::123456789012:user/Jorge_Souza"
                ]
            },
            {
                "reaction": {
                    "emoji": "??",
                    "shortCode": "thumbsdown",
                    "unicode": "U+1F44E"
                },
                "users": [
                    "arn:aws:iam::123456789012:user/Nikhil_Jayashankar"
                ]
            },
            {
                "reaction": {
                    "emoji": "??",
                    "shortCode": "confused",
                    "unicode": "U+1F615"
                },
                "users": [
                    "arn:aws:iam::123456789012:user/Saanvi_Sarkar"
                ]
            }
        ]
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[在 AWS CodeCommit 中评论提交](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-commit-comment.html#how-to-commit-comment-cli-commit-emoji-view)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetCommentReactions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-comment-reactions.html)。

### `get-comment`
<a name="codecommit_GetComment_cli_topic"></a>

以下代码示例演示了如何使用 `get-comment`。

**AWS CLI**  
**查看有关评论的详细信息**  
此示例演示如何查看系统生成的评论 ID 为 `ff30b348EXAMPLEb9aa670f` 的评论的详细信息。  

```
aws codecommit get-comment \
    --comment-id ff30b348EXAMPLEb9aa670f
```
输出：  

```
{
    "comment": {
        "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
        "clientRequestToken": "123Example",
        "commentId": "ff30b348EXAMPLEb9aa670f",
        "content": "Whoops - I meant to add this comment to the line, but I don't see how to delete it.",
        "creationDate": 1508369768.142,
        "deleted": false,
        "commentId": "",
        "lastModifiedDate": 1508369842.278,
        "callerReactions": [],
        "reactionCounts":
        {
            "SMILE" : 6,
            "THUMBSUP" : 1
        }
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetComment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-comment.html)。

### `get-comments-for-compared-commit`
<a name="codecommit_GetCommentsForComparedCommit_cli_topic"></a>

以下代码示例演示了如何使用 `get-comments-for-compared-commit`。

**AWS CLI**  
**查看对提交进行的评论**  
此示例演示了如何查看对名为 `MyDemoRepo` 的存储库中两个提交之间的比较做出的评论。  

```
aws codecommit get-comments-for-compared-commit \
    --repository-name MyDemoRepo \
    --before-commit-ID 6e147360EXAMPLE \
    --after-commit-id 317f8570EXAMPLE
```
输出：  

```
{
    "commentsForComparedCommitData": [
        {
            "afterBlobId": "1f330709EXAMPLE",
            "afterCommitId": "317f8570EXAMPLE",
            "beforeBlobId": "80906a4cEXAMPLE",
            "beforeCommitId": "6e147360EXAMPLE",
            "comments": [
                {
                    "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
                    "clientRequestToken": "123Example",
                    "commentId": "ff30b348EXAMPLEb9aa670f",
                    "content": "Whoops - I meant to add this comment to the line, not the file, but I don't see how to delete it.",
                    "creationDate": 1508369768.142,
                    "deleted": false,
                    "CommentId": "123abc-EXAMPLE",
                    "lastModifiedDate": 1508369842.278,
                    "callerReactions": [],
                    "reactionCounts":
                    {
                        "SMILE" : 6,
                        "THUMBSUP" : 1
                    }
                },
                {
                    "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
                    "clientRequestToken": "123Example",
                    "commentId": "553b509bEXAMPLE56198325",
                    "content": "Can you add a test case for this?",
                    "creationDate": 1508369612.240,
                    "deleted": false,
                    "commentId": "456def-EXAMPLE",
                    "lastModifiedDate": 1508369612.240,
                    "callerReactions": [],
                    "reactionCounts":
                    {
                        "THUMBSUP" : 2
                    }
                }
            ],
            "location": {
                "filePath": "cl_sample.js",
                "filePosition": 1232,
                "relativeFileVersion": "after"
            },
            "repositoryName": "MyDemoRepo"
        }
    ],
    "nextToken": "exampleToken"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetCommentsForComparedCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-comments-for-compared-commit.html)。

### `get-comments-for-pull-request`
<a name="codecommit_GetCommentsForPullRequest_cli_topic"></a>

以下代码示例演示了如何使用 `get-comments-for-pull-request`。

**AWS CLI**  
**查看拉取请求的评论**  
此示例演示了如何查看名为 `MyDemoRepo` 的存储库中的拉取请求的评论。  

```
aws codecommit get-comments-for-pull-request \
    --repository-name MyDemoRepo \
    --before-commit-ID 317f8570EXAMPLE \
    --after-commit-id 5d036259EXAMPLE
```
输出：  

```
{
    "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"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetCommentsForPullRequest](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-comments-for-pull-request.html)。

### `get-commit`
<a name="codecommit_GetCommit_cli_topic"></a>

以下代码示例演示了如何使用 `get-commit`。

**AWS CLI**  
**查看有关存储库中提交的信息**  
此示例显示 AWS CodeCommit 存储库中名为“MyDemoRepo”的提交的详细信息，该提交的系统生成 ID 为“7e9fd3091thisisanexamplethisisanexample1”。  
命令:  

```
aws codecommit get-commit --repository-name MyDemoRepo --commit-id 7e9fd3091thisisanexamplethisisanexample1
```
输出：  

```
{
  "commit": {
      "additionalData": "",
      "committer": {
          "date": "1484167798 -0800",
          "name": "Mary Major",
          "email": "mary_major@example.com"
      },
      "author": {
          "date": "1484167798 -0800",
          "name": "Mary Major",
          "email": "mary_major@example.com"
      },
      "treeId": "347a3408thisisanexampletreeidexample",
      "parents": [
          "7aa87a031thisisanexamplethisisanexample1"
      ],
      "message": "Fix incorrect variable name"
  }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-commit.html)。

### `get-differences`
<a name="codecommit_GetDifferences_cli_topic"></a>

以下代码示例演示了如何使用 `get-differences`。

**AWS CLI**  
**获取有关存储库中提交说明符差异的信息**  
此示例显示了 AWS CodeCommit 存储库中名为 MyDemoRepo 的重命名文件夹中查看两个提交说明符（分支、标记、HEAD 或其他完全限定参考，例如提交 ID）之间更改的元数据信息。该示例包括几个非必备选项，包括 --before-commit-specifier、--before-path 和 --after-path，以便更全面地说明如何使用这些选项来限制结果。响应包括文件模式权限。  
命令:  

```
aws codecommit get-differences --repository-name MyDemoRepo --before-commit-specifier 955bba12thisisanexamplethisisanexample --after-commit-specifier 14a95463thisisanexamplethisisanexample --before-path tmp/example-folder --after-path tmp/renamed-folder
```
输出：  

```
{
  "differences": [
      {
          "afterBlob": {
              "path": "blob.txt",
              "blobId": "2eb4af3b1thisisanexamplethisisanexample1",
              "mode": "100644"
          },
          "changeType": "M",
          "beforeBlob": {
              "path": "blob.txt",
              "blobId": "bf7fcf281thisisanexamplethisisanexample1",
              "mode": "100644"
          }
      }
  ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetDifferences](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-differences.html)。

### `get-file`
<a name="codecommit_GetFile_cli_topic"></a>

以下代码示例演示了如何使用 `get-file`。

**AWS CLI**  
**获取 AWS CodeCommit 存储库中文件的 base-64 编码内容**  
以下 `get-file` 示例演示如何从名为 `MyDemoRepo` 的存储库中名为 `main` 的分支中获取名为 `README.md` 的文件的 base-64 编码内容。  

```
aws codecommit get-file \
    --repository-name MyDemoRepo \
    --commit-specifier main \
    --file-path README.md
```
输出：  

```
{
    "blobId":"559b44fEXAMPLE",
    "commitId":"c5709475EXAMPLE",
    "fileContent":"IyBQaHVzEXAMPLE",
    "filePath":"README.md",
    "fileMode":"NORMAL",
    "fileSize":1563
}
```
有关更多信息，请参阅《AWS CodeCommit API 参考》**指南中的 [GetFile](https://docs.aws.amazon.com/codecommit/latest/APIReference/API_GetFile.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetFile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-file.html)。

### `get-folder`
<a name="codecommit_GetFolder_cli_topic"></a>

以下代码示例演示了如何使用 `get-folder`。

**AWS CLI**  
**获取 AWS CodeCommit 存储库中某个文件夹的内容**  
以下 `get-folder` 示例演示如何从名为 `MyDemoRepo` 的存储库中获取顶层文件夹的内容。  

```
aws codecommit get-folder --repository-name MyDemoRepo --folder-path ""
```
输出：  

```
{
    "commitId":"c5709475EXAMPLE",
    "files":[
        {
            "absolutePath":".gitignore",
            "blobId":"74094e8bEXAMPLE",
            "fileMode":"NORMAL",
            "relativePath":".gitignore"
        },
        {
            "absolutePath":"Gemfile",
            "blobId":"9ceb72f6EXAMPLE",
            "fileMode":"NORMAL",
            "relativePath":"Gemfile"
        },
        {
            "absolutePath":"Gemfile.lock",
            "blobId":"795c4a2aEXAMPLE",
            "fileMode":"NORMAL",
            "relativePath":"Gemfile.lock"
        },
        {
            "absolutePath":"LICENSE.txt",
            "blobId":"0c7932c8EXAMPLE",
            "fileMode":"NORMAL",
            "relativePath":"LICENSE.txt"
        },
        {
            "absolutePath":"README.md",
            "blobId":"559b44feEXAMPLE",
            "fileMode":"NORMAL",
            "relativePath":"README.md"
        }
    ],
    "folderPath":"",
    "subFolders":[
        {
            "absolutePath":"public",
            "relativePath":"public",
            "treeId":"d5e92ae3aEXAMPLE"
        },
        {
            "absolutePath":"tmp",
            "relativePath":"tmp",
            "treeId":"d564d0bcEXAMPLE"
        }
    ],
    "subModules":[],
    "symbolicLinks":[],
    "treeId":"7b3c4dadEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit API 参考》**指南中的 GetFolder。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetFolder](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-folder.html)。

### `get-merge-commit`
<a name="codecommit_GetMergeCommit_cli_topic"></a>

以下代码示例演示了如何使用 `get-merge-commit`。

**AWS CLI**  
**获取有关合并提交的详细信息**  
以下 `get-merge-commit` 示例显示有关在名为 `MyDemoRepo` 的存储库中，名为 `bugfix-bug1234` 的源分支与名为 `main` 的目标分支合并提交的详细信息。  

```
aws codecommit get-merge-commit \
    --source-commit-specifier bugfix-bug1234 \
    --destination-commit-specifier main \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "sourceCommitId": "c5709475EXAMPLE",
    "destinationCommitId": "317f8570EXAMPLE",
    "baseCommitId": "fb12a539EXAMPLE",
    "mergeCommitId": "ffc4d608eEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[查看提交的详细信息](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-view-commit-details.html#how-to-view-commit-details-cli-merge-commit)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetMergeCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-merge-commit.html)。

### `get-merge-conflicts`
<a name="codecommit_GetMergeConflicts_cli_topic"></a>

以下代码示例演示了如何使用 `get-merge-conflicts`。

**AWS CLI**  
**查看拉取请求是否存在合并冲突**  
以下 `get-merge-conflicts` 示例显示在名为 `MyDemoRepo` 的存储库中，名为 `feature-randomizationfeature` 的源分支的提示和名为“main”的目标分支的提示之间是否存在合并冲突。  

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

```
{
    "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"
            }
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetMergeConflicts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-merge-conflicts.html)。

### `get-merge-options`
<a name="codecommit_GetMergeOptions_cli_topic"></a>

以下代码示例演示了如何使用 `get-merge-options`。

**AWS CLI**  
**获取有关合并两个指定分支的合并选项的信息**  
以下 `get-merge-options` 示例确定在名为 `MyDemoRepo` 的存储库中，合并名为 `bugfix-bug1234` 的源分支与名为 `main` 的目标分支时可用的合并选项。  

```
aws codecommit get-merge-options \
    --source-commit-specifier bugfix-bug1234 \
    --destination-commit-specifier main \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "mergeOptions": [
        "FAST_FORWARD_MERGE",
        "SQUASH_MERGE",
        "THREE_WAY_MERGE"
    ],
    "sourceCommitId": "18059494EXAMPLE",
    "destinationCommitId": "ffd3311dEXAMPLE",
    "baseCommitId": "ffd3311dEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[解决拉取请求中的冲突](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-resolve-conflict-pull-request.html#get-merge-options)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetMergeOptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-merge-options.html)。

### `get-pull-request-approval-states`
<a name="codecommit_GetPullRequestApprovalStates_cli_topic"></a>

以下代码示例演示了如何使用 `get-pull-request-approval-states`。

**AWS CLI**  
**查看拉取请求的审批**  
以下 `get-pull-request-approval-states` 示例返回指定拉取请求的审批。  

```
aws codecommit get-pull-request-approval-states \
    --pull-request-id 8 \
    --revision-id 9f29d167EXAMPLE
```
输出：  

```
{
    "approvals": [
        {
            "userArn": "arn:aws:iam::123456789012:user/Mary_Major",
            "approvalState": "APPROVE"
        }
    ]
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[查看拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-view-pull-request.html#get-pull-request-approval-state)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetPullRequestApprovalStates](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-pull-request-approval-states.html)。

### `get-pull-request-override-state`
<a name="codecommit_GetPullRequestOverrideState_cli_topic"></a>

以下代码示例演示了如何使用 `get-pull-request-override-state`。

**AWS CLI**  
**获取有关拉取请求覆盖状态的信息**  
以下 `get-pull-request-override-state` 示例返回指定拉取请求的覆盖状态。在此示例中，名为 Mary Major 的用户覆盖了拉取请求的审批规则，因此输出返回的值为 `true`：  

```
aws codecommit get-pull-request-override-state \
    --pull-request-id 34  \
    --revision-id 9f29d167EXAMPLE
```
输出：  

```
{
    "overridden": true,
    "overrider": "arn:aws:iam::123456789012:user/Mary_Major"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[在拉取请求上覆盖审批规则](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-override-approval-rules.html#get-override-status)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetPullRequestOverrideState](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-pull-request-override-state.html)。

### `get-pull-request`
<a name="codecommit_GetPullRequest_cli_topic"></a>

以下代码示例演示了如何使用 `get-pull-request`。

**AWS CLI**  
**查看拉取请求的详细信息**  
此示例演示如何查看 ID 为 `27` 的拉取请求的相关信息。  

```
aws codecommit get-pull-request \
    --pull-request-id 27
```
输出：  

```
{
    "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"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetPullRequest](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-pull-request.html)。

### `get-repository-triggers`
<a name="codecommit_GetRepositoryTriggers_cli_topic"></a>

以下代码示例演示了如何使用 `get-repository-triggers`。

**AWS CLI**  
**获取有关存储库中触发器的信息**  
此示例显示有关为名为 `MyDemoRepo` 的 AWS CodeCommit 存储库配置的触发器的详细信息。  

```
aws codecommit get-repository-triggers \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "configurationId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
    "triggers": [
        {
            "destinationArn": "arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic",
            "branches": [
                "main",
                "preprod"
            ],
            "name": "MyFirstTrigger",
            "customData": "",
            "events": [
                "all"
            ]
        },
        {
            "destinationArn": "arn:aws:lambda:us-east-1:111111111111:function:MyCodeCommitPythonFunction",
            "branches": [],
            "name": "MySecondTrigger",
            "customData": "EXAMPLE",
            "events": [
                "all"
            ]
        }
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetRepositoryTriggers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-repository-triggers.html)。

### `get-repository`
<a name="codecommit_GetRepository_cli_topic"></a>

以下代码示例演示了如何使用 `get-repository`。

**AWS CLI**  
**获取有关存储库的信息**  
此示例显示了有关 AWS CodeCommit 存储库的详细信息。  

```
aws codecommit get-repository \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "repositoryMetadata": {
        "creationDate": 1429203623.625,
        "defaultBranch": "main",
        "repositoryName": "MyDemoRepo",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/v1/repos/MyDemoRepo",
        "lastModifiedDate": 1430783812.0869999,
        "repositoryDescription": "My demonstration repository",
        "cloneUrlHttp": "https://codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
        "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
        "Arn": "arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
        "accountId": "111111111111"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-repository.html)。

### `list-approval-rule-templates`
<a name="codecommit_ListApprovalRuleTemplates_cli_topic"></a>

以下代码示例演示了如何使用 `list-approval-rule-templates`。

**AWS CLI**  
**列出 AWS 区域中的所有审批规则模板**  
以下 `list-approval-rule-templates` 示例列出指定区域中的所有审批规则模板。如果未将 AWS 区域指定为参数，则该命令将返回用于运行该命令的 AWS CLI 配置文件中指定区域的审批规则模板。  

```
aws codecommit list-approval-rule-templates \
    --region us-east-2
```
输出：  

```
{
    "approvalRuleTemplateNames": [
        "2-approver-rule-for-main",
        "1-approver-rule-for-all-pull-requests"
    ]
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#list-templates)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListApprovalRuleTemplates](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-approval-rule-templates.html)。

### `list-associated-approval-rule-templates-for-repository`
<a name="codecommit_ListAssociatedApprovalRuleTemplatesForRepository_cli_topic"></a>

以下代码示例演示了如何使用 `list-associated-approval-rule-templates-for-repository`。

**AWS CLI**  
**列出与存储库关联的所有模板**  
以下 `list-associated-approval-rule-templates-for-repository` 示例列出所有与名为 `MyDemoRepo` 的存储库关联的审批规则模板。  

```
aws codecommit list-associated-approval-rule-templates-for-repository \
    --repository-name MyDemoRepo
```
输出：  

```
{
  "approvalRuleTemplateNames": [
    "2-approver-rule-for-main",
    "1-approver-rule-for-all-pull-requests"
  ]
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#list-associated-templates)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListAssociatedApprovalRuleTemplatesForRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-associated-approval-rule-templates-for-repository.html)。

### `list-branches`
<a name="codecommit_ListBranches_cli_topic"></a>

以下代码示例演示了如何使用 `list-branches`。

**AWS CLI**  
**查看分支名称列表**  
此示例列出 AWS CodeCommit 存储库中的所有分支名称。  

```
aws codecommit list-branches \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "branches": [
        "MyNewBranch",
        "main"
    ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListBranches](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-branches.html)。

### `list-pull-requests`
<a name="codecommit_ListPullRequests_cli_topic"></a>

以下代码示例演示了如何使用 `list-pull-requests`。

**AWS CLI**  
**查看存储库中拉取请求的列表**  
此示例演示了如何列出名为“MyDemoRepo”的 AWS CodeCommit 存储库中的由 ARN 为“arn:aws:iam::111111111111:user/Li\$1Juan”且状态为“CLOSED”的 IAM 用户创建的拉取请求：  

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

```
{
 "nextToken": "",
 "pullRequestIds": ["2","12","16","22","23","35","30","39","47"]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListPullRequests](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-pull-requests.html)。

### `list-repositories-for-approval-rule-template`
<a name="codecommit_ListRepositoriesForApprovalRuleTemplate_cli_topic"></a>

以下代码示例演示了如何使用 `list-repositories-for-approval-rule-template`。

**AWS CLI**  
**列出与模板关联的所有存储库**  
以下 `list-repositories-for-approval-rule-template` 示例列出与指定审批规则模板关联的所有存储库。  

```
aws codecommit list-repositories-for-approval-rule-template \
    --approval-rule-template-name 2-approver-rule-for-main
```
输出：  

```
{
    "repositoryNames": [
        "MyDemoRepo",
        "MyClonedRepo"
    ]
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#list-associated-repositories)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListRepositoriesForApprovalRuleTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-repositories-for-approval-rule-template.html)。

### `list-repositories`
<a name="codecommit_ListRepositories_cli_topic"></a>

以下代码示例演示了如何使用 `list-repositories`。

**AWS CLI**  
**查看存储库列表**  
此示例列出了与用户的 AWS 帐户关联的所有 AWS CodeCommit 存储库。  
命令:  

```
aws codecommit list-repositories
```
输出：  

```
{
  "repositories": [
      {
         "repositoryName": "MyDemoRepo"
         "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
      },
      {
         "repositoryName": "MyOtherDemoRepo"
         "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE"
      }
  ]
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-repositories.html)。

### `list-tags-for-resource`
<a name="codecommit_ListTagsForResource_cli_topic"></a>

以下代码示例演示了如何使用 `list-tags-for-resource`。

**AWS CLI**  
**查看存储库的 AWS 标签**  
以下 `list-tags-for-resource` 示例列出指定存储库的标签键和标签值。  

```
aws codecommit list-tags-for-resource \
    --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo
```
输出：  

```
{
    "tags": {
        "Status": "Secret",
        "Team": "Saanvi"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[查看存储库的标签](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-tag-repository-list.html#how-to-tag-repository-list-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-tags-for-resource.html)。

### `merge-branches-by-fast-forward`
<a name="codecommit_MergeBranchesByFastForward_cli_topic"></a>

以下代码示例演示了如何使用 `merge-branches-by-fast-forward`。

**AWS CLI**  
**使用快速转发合并策略合并两个分支**  
以下 `merge-branches-by-fast-forward` 示例将指定的源分支与名为 `MyDemoRepo` 的存储库中的指定目标分支合并。  

```
aws codecommit merge-branches-by-fast-forward \
    --source-commit-specifier bugfix-bug1234 \
    --destination-commit-specifier bugfix-bug1233 \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "commitId": "4f178133EXAMPLE",
    "treeId": "389765daEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[比较和合并分支](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-compare-branches.html#merge-branches-by-fast-forward)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergeBranchesByFastForward](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-branches-by-fast-forward.html)。

### `merge-branches-by-squash`
<a name="codecommit_MergeBranchesBySquash_cli_topic"></a>

以下代码示例演示了如何使用 `merge-branches-by-squash`。

**AWS CLI**  
**使用 squash 合并策略合并两个分支**  
以下 `merge-branches-by-squash` 示例将指定的源分支与名为 `MyDemoRepo` 的存储库中的指定目标分支合并。  

```
aws codecommit merge-branches-by-squash \
    --source-commit-specifier bugfix-bug1234 \
    --destination-commit-specifier bugfix-bug1233 \
    --author-name "Maria Garcia" \
    --email "maria_garcia@example.com" \
    --commit-message "Merging two fix branches to prepare for a general patch." \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "commitId": "4f178133EXAMPLE",
    "treeId": "389765daEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[比较和合并分支](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-compare-branches.html#merge-branches-by-squash)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergeBranchesBySquash](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-branches-by-squash.html)。

### `merge-branches-by-three-way`
<a name="codecommit_MergeBranchesByThreeWay_cli_topic"></a>

以下代码示例演示了如何使用 `merge-branches-by-three-way`。

**AWS CLI**  
**使用三向合并策略合并两个分支**  
以下 `merge-branches-by-three-way` 示例将指定的源分支与名为 `MyDemoRepo` 的存储库中的指定目标分支合并。  

```
aws codecommit merge-branches-by-three-way \
    --source-commit-specifier main \
    --destination-commit-specifier bugfix-bug1234 \
    --author-name "Jorge Souza" --email "jorge_souza@example.com" \
    --commit-message "Merging changes from main to bugfix branch before additional testing." \
    --repository-name MyDemoRepo
```
输出：  

```
{
    "commitId": "4f178133EXAMPLE",
    "treeId": "389765daEXAMPLE"
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[比较和合并分支](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-compare-branches.html#merge-branches-by-three-way)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergeBranchesByThreeWay](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-branches-by-three-way.html)。

### `merge-pull-request-by-fast-forward`
<a name="codecommit_MergePullRequestByFastForward_cli_topic"></a>

以下代码示例演示了如何使用 `merge-pull-request-by-fast-forward`。

**AWS CLI**  
**合并并关闭拉取请求**  
此示例演示了如何在名为 `MyDemoRepo` 的存储库中合并并关闭 ID 为 47 且源提交 ID 为“99132ab0EXAMPLE”的拉取请求。  

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

```
{
    "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"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[合并拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-merge-pull-request.html#merge-pull-request-by-fast-forward)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergePullRequestByFastForward](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-pull-request-by-fast-forward.html)。

### `merge-pull-request-by-squash`
<a name="codecommit_MergePullRequestBySquash_cli_topic"></a>

以下代码示例演示了如何使用 `merge-pull-request-by-squash`。

**AWS CLI**  
**使用 squash 合并策略合并拉取请求**  
以下 `merge-pull-request-by-squash` 示例在名为 `MyDemoRepo` 的存储库中使用 ACCEPT\$1SOURCE 的冲突解决策略合并并关闭指定的拉取请求。  

```
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 \
    --name "Jorge Souza" --email "jorge_souza@example.com" \
    --commit-message "Merging pull request 47 by squash and accepting source in merge conflicts"
```
输出：  

```
{
    "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"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[合并拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-merge-pull-request.html#merge-pull-request-by-squash)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergePullRequestBySquash](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-pull-request-by-squash.html)。

### `merge-pull-request-by-three-way`
<a name="codecommit_MergePullRequestByThreeWay_cli_topic"></a>

以下代码示例演示了如何使用 `merge-pull-request-by-three-way`。

**AWS CLI**  
**使用三向合并策略合并拉取请求**  
以下 `merge-pull-request-by-three-way` 示例在名为 `MyDemoRepo` 的存储库中使用冲突详情和冲突解决策略的默认选项合并并关闭指定的拉取请求。  

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

```
{
    "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"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[合并拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-merge-pull-request.html#merge-pull-request-by-three-way)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [MergePullRequestByThreeWay](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/merge-pull-request-by-three-way.html)。

### `override-pull-request-approval-rules`
<a name="codecommit_OverridePullRequestApprovalRules_cli_topic"></a>

以下代码示例演示了如何使用 `override-pull-request-approval-rules`。

**AWS CLI**  
**覆盖拉取请求的审批规则要求**  
以下 `override-pull-request-approval-rules` 示例覆盖指定拉取请求的审批规则。要改为撤消覆盖，请将 `--override-status` 参数值设置为 `REVOKE`。  

```
aws codecommit override-pull-request-approval-rules \
    --pull-request-id 34  \
    --revision-id 927df8d8EXAMPLE \
    --override-status OVERRIDE
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[在拉取请求上覆盖审批规则](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-override-approval-rules.html#override-approval-rules)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [OverridePullRequestApprovalRules](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/override-pull-request-approval-rules.html)。

### `post-comment-for-compared-commit`
<a name="codecommit_PostCommentForComparedCommit_cli_topic"></a>

以下代码示例演示了如何使用 `post-comment-for-compared-commit`。

**AWS CLI**  
**创建提交评论**  
此示例演示了如何在名为 `MyDemoRepo` 的存储库中的两个提交之间的比较中，在 `cl_sample.js` 文件的更改上添加评论 `"Can you add a test case for this?"`。  

```
aws codecommit post-comment-for-compared-commit \
    --repository-name MyDemoRepo \
    --before-commit-id 317f8570EXAMPLE \
    --after-commit-id 5d036259EXAMPLE \
    --client-request-token 123Example \
    --content "Can you add a test case for this?" \
    --location filePath=cl_sample.js,filePosition=1232,relativeFileVersion=AFTER
```
输出：  

```
{
    "afterBlobId": "1f330709EXAMPLE",
    "afterCommitId": "317f8570EXAMPLE",
    "beforeBlobId": "80906a4cEXAMPLE",
    "beforeCommitId": "6e147360EXAMPLE",
    "comment": {
        "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
        "clientRequestToken": "",
        "commentId": "553b509bEXAMPLE56198325",
        "content": "Can you add a test case for this?",
        "creationDate": 1508369612.203,
        "deleted": false,
        "commentId": "abc123-EXAMPLE",
        "lastModifiedDate": 1508369612.203,
        "callerReactions": [],
        "reactionCounts": []
    },
    "location": {
        "filePath": "cl_sample.js",
        "filePosition": 1232,
        "relativeFileVersion": "AFTER"
    ,
    "repositoryName": "MyDemoRepo"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PostCommentForComparedCommit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/post-comment-for-compared-commit.html)。

### `post-comment-for-pull-request`
<a name="codecommit_PostCommentForPullRequest_cli_topic"></a>

以下代码示例演示了如何使用 `post-comment-for-pull-request`。

**AWS CLI**  
**向拉取请求添加评论**  
以下 `post-comment-for-pull-request` 示例添加评论“这些内容似乎没有在任何地方使用。要移除它们吗？” ，该评论是在名为 `MyDemoRepo` 的存储库中 ID 为 `47` 的拉取请求内，针对 `ahs_count.py` 文件的更改所添加的评论。  

```
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
```
输出：  

```
{
     "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,
            "CommentId": "",
            "lastModifiedDate": 1508369622.123,
            "callerReactions": [],
            "reactionCounts": []
        },
        "location": {
            "filePath": "ahs_count.py",
            "filePosition": 367,
            "relativeFileVersion": "AFTER"
         },
     "repositoryName": "MyDemoRepo",
     "pullRequestId": "47"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PostCommentForPullRequest](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/post-comment-for-pull-request.html)。

### `post-comment-reply`
<a name="codecommit_PostCommentReply_cli_topic"></a>

以下代码示例演示了如何使用 `post-comment-reply`。

**AWS CLI**  
**回复提交或拉取请求中的评论**  
此示例演示如何在系统生成的 ID 为 `abcd1234EXAMPLEb5678efgh` 的评论中添加回复 `"Good catch. I'll remove them."`。  

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

```
{
    "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,
        "CommentId": "abcd1234EXAMPLEb5678efgh",
        "lastModifiedDate": 150836912.221,
        "callerReactions": [],
        "reactionCounts": []
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PostCommentReply](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/post-comment-reply.html)。

### `put-comment-reaction`
<a name="codecommit_PutCommentReaction_cli_topic"></a>

以下代码示例演示了如何使用 `put-comment-reaction`。

**AWS CLI**  
**使用表情符号回复对提交的评论**  
以下 `put-comment-reaction` 示例使用反应值为 `:thumbsup:` 的表情符号回复一条 ID 为 `abcd1234EXAMPLEb5678efgh` 的评论。  

```
aws codecommit put-comment-reaction \
    --comment-id abcd1234EXAMPLEb5678efgh \
    --reaction-value :thumbsup:
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[在 AWS CodeCommit 中评论提交](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-commit-comment.html#how-to-commit-comment-cli-commit-reply-emoji)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutCommentReaction](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/put-comment-reaction.html)。

### `put-file`
<a name="codecommit_PutFile_cli_topic"></a>

以下代码示例演示了如何使用 `put-file`。

**AWS CLI**  
**向存储库添加文件**  
以下 `put-file` 示例将“ExampleSolution.py”文件添加到名为“MyDemoRepo”的存储库中的“feature-randomizationfeature”分支，该分支最新提交的 ID 为“4c925148EXAMPLE”。  

```
aws codecommit put-file \
    --repository-name MyDemoRepo \
    --branch-name feature-randomizationfeature \
    --file-content file://MyDirectory/ExampleSolution.py \
    --file-path /solutions/ExampleSolution.py \
    --parent-commit-id 4c925148EXAMPLE \
    --name "Maria Garcia" \
    --email "maria_garcia@example.com" \
    --commit-message "I added a third randomization routine."
```
输出：  

```
{
    "blobId": "2eb4af3bEXAMPLE",
    "commitId": "317f8570EXAMPLE",
    "treeId": "347a3408EXAMPLE"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutFile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/put-file.html)。

### `put-repository-triggers`
<a name="codecommit_PutRepositoryTriggers_cli_topic"></a>

以下代码示例演示了如何使用 `put-repository-triggers`。

**AWS CLI**  
**在存储库中添加或更新触发器**  
此示例演示如何使用已创建的 JSON 文件（此处名为 MyTriggers.json）更新名为“MyFirstTrigger”和“MySecondTrigger”的触发器，该文件包含名为 MyDemoRepo 的存储库的所有触发器的结构。要了解如何获取现有触发器的 JSON，请参阅 get-repository-triggers 命令。  

```
aws codecommit put-repository-triggers \
    --repository-name MyDemoRepo file://MyTriggers.json
```
 的内容`MyTriggers.json`：  

```
{
    "repositoryName": "MyDemoRepo",
    "triggers": [
        {
            "destinationArn": "arn:aws:sns:us-east-1:80398EXAMPLE:MyCodeCommitTopic",
            "branches": [
                "main",
                "preprod"
            ],
            "name": "MyFirstTrigger",
            "customData": "",
            "events": [
                "all"
            ]
        },
        {
            "destinationArn": "arn:aws:lambda:us-east-1:111111111111:function:MyCodeCommitPythonFunction",
            "branches": [],
            "name": "MySecondTrigger",
            "customData": "EXAMPLE",
            "events": [
                "all"
            ]
        }
    ]
}
```
输出：  

```
{
    "configurationId": "6fa51cd8-35c1-EXAMPLE"
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutRepositoryTriggers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/put-repository-triggers.html)。

### `tag-resource`
<a name="codecommit_TagResource_cli_topic"></a>

以下代码示例演示了如何使用 `tag-resource`。

**AWS CLI**  
**向现有存储库添加 AWS 标签**  
以下 `tag-resource` 示例使用两个标签对指定存储库进行标记。  

```
aws codecommit tag-resource \
    --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo \
    --tags Status=Secret,Team=Saanvi
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[向存储库添加标签](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-tag-repository-add.html#how-to-tag-repository-add-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/tag-resource.html)。

### `test-repository-triggers`
<a name="codecommit_TestRepositoryTriggers_cli_topic"></a>

以下代码示例演示了如何使用 `test-repository-triggers`。

**AWS CLI**  
**在存储库中测试触发器**  
此示例演示了如何在名为 MyDemoRepo 的 AWS CodeCommit 存储库中测试名为“MyFirstTrigger”的触发器。在此示例中，存储库中的事件会触发 Amazon Simple Notification Service（Amazon SNS）主题通知。  
命令:  

```
aws codecommit test-repository-triggers --repository-name MyDemoRepo --triggers name=MyFirstTrigger,destinationArn=arn:aws:sns:us-east-1:111111111111:MyCodeCommitTopic,branches=mainline,preprod,events=all
```
输出：  

```
{
  "successfulExecutions": [
      "MyFirstTrigger"
  ],
  "failedExecutions": []
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TestRepositoryTriggers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/test-repository-triggers.html)。

### `untag-resource`
<a name="codecommit_UntagResource_cli_topic"></a>

以下代码示例演示了如何使用 `untag-resource`。

**AWS CLI**  
**移除存储库的 AWS 标签**  
以下 `untag-resource` 示例移除名为 `MyDemoRepo` 的存储库中带有指定键的标签。  

```
aws codecommit untag-resource \
    --resource-arn arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo \
    --tag-keys Status
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[移除存储库的标签](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-tag-repository-delete.html#how-to-tag-repository-delete-cli)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/untag-resource.html)。

### `update-approval-rule-template-content`
<a name="codecommit_UpdateApprovalRuleTemplateContent_cli_topic"></a>

以下代码示例演示了如何使用 `update-approval-rule-template-content`。

**AWS CLI**  
**更新审批规则模板的内容**  
以下 `update-approval-rule-template-content` 示例更改指定审批规则模板的内容，重新定义 `CodeCommitReview` 角色用户的审批池。  

```
aws codecommit update-approval-rule-template-content \
    --approval-rule-template-name 1-approver-rule  \
    --new-rule-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"
```
输出：  

```
{
    "approvalRuleTemplate": {
        "creationDate": 1571352720.773,
        "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool",
        "lastModifiedDate": 1571358728.41,
        "approvalRuleTemplateId": "41de97b7-EXAMPLE",
        "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
        "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
        "ruleContentSha256": "2f6c21a5EXAMPLE",
        "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan"
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#update-template-content)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateApprovalRuleTemplateContent](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-approval-rule-template-content.html)。

### `update-approval-rule-template-description`
<a name="codecommit_UpdateApprovalRuleTemplateDescription_cli_topic"></a>

以下代码示例演示了如何使用 `update-approval-rule-template-description`。

**AWS CLI**  
**更新审批规则模板的描述**  
以下 `update-approval-rule-template-description` 示例将指定的审批规则模板更改为 `Requires 1 approval for all pull requests from the CodeCommitReview pool`：  

```
aws codecommit update-approval-rule-template-description \
    --approval-rule-template-name 1-approver-rule-for-all-pull-requests  \
    --approval-rule-template-description "Requires 1 approval for all pull requests from the CodeCommitReview pool"
```
输出：  

```
{
  "approvalRuleTemplate": {
    "creationDate": 1571352720.773,
    "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool",
    "lastModifiedDate": 1571358728.41,
    "approvalRuleTemplateId": "41de97b7-EXAMPLE",
    "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
    "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
    "ruleContentSha256": "2f6c21a5EXAMPLE",
    "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan"
  }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#update-template-description)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateApprovalRuleTemplateDescription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-approval-rule-template-description.html)。

### `update-approval-rule-template-name`
<a name="codecommit_UpdateApprovalRuleTemplateName_cli_topic"></a>

以下代码示例演示了如何使用 `update-approval-rule-template-name`。

**AWS CLI**  
**更新审批规则模板的名称**  
以下 `update-approval-rule-template-name` 示例将审批规则模板的名称从 `1-approver-rule` 更改为 1-approver-rule-for-all-pull-requests`。  

```
aws codecommit update-approval-rule-template-name \
    --old-approval-rule-template-name 1-approver-rule  \
    --new-approval-rule-template-name 1-approver-rule-for-all-pull-requests
```
输出：  

```
{
  "approvalRuleTemplate": {
    "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
    "lastModifiedDate": 1571358241.619,
    "approvalRuleTemplateId": "41de97b7-EXAMPLE",
    "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
    "creationDate": 1571352720.773,
    "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
    "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team.",
    "ruleContentSha256": "2f6c21a5cEXAMPLE"
  }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[管理审批规则模板](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-manage-templates.html#update-template-description)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateApprovalRuleTemplateName](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-approval-rule-template-name.html)。

### `update-comment`
<a name="codecommit_UpdateComment_cli_topic"></a>

以下代码示例演示了如何使用 `update-comment`。

**AWS CLI**  
**更新提交评论**  
此示例演示如何将内容 `"Fixed as requested. I'll update the pull request."` 添加到 ID 为 `442b498bEXAMPLE5756813` 的评论中。  

```
aws codecommit update-comment \
    --comment-id 442b498bEXAMPLE5756813 \
    --content "Fixed as requested. I'll update the pull request."
```
输出：  

```
{
    "comment": {
        "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
        "clientRequestToken": "",
        "commentId": "442b498bEXAMPLE5756813",
        "content": "Fixed as requested. I'll update the pull request.",
        "creationDate": 1508369929.783,
        "deleted": false,
        "lastModifiedDate": 1508369929.287,
        "callerReactions": [],
        "reactionCounts":
            {
                "THUMBSUP" : 2
            }
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateComment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-comment.html)。

### `update-default-branch`
<a name="codecommit_UpdateDefaultBranch_cli_topic"></a>

以下代码示例演示了如何使用 `update-default-branch`。

**AWS CLI**  
**更改存储库的默认分支**  
此示例更改 AWS CodeCommit 存储库的默认分支。该命令只在出现错误时生成输出。  
命令:  

```
aws codecommit update-default-branch --repository-name MyDemoRepo --default-branch-name MyNewBranch
```
输出：  

```
None.
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateDefaultBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-default-branch.html)。

### `update-pull-request-approval-rule-content`
<a name="codecommit_UpdatePullRequestApprovalRuleContent_cli_topic"></a>

以下代码示例演示了如何使用 `update-pull-request-approval-rule-content`。

**AWS CLI**  
**编辑拉取请求的审批规则**  
以下 `update-pull-request-approval-rule-content` 示例更新她指定的审批规则，要求从包括 `123456789012` AWS 账户中任何 IAM 用户的审批池中获得一个用户审批。  

```
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/*\"]}]}}"
```
输出：  

```
{
    "approvalRule": {
        "approvalRuleContent": "{Version: 2018-11-08, Statements: [{Type: \"Approvers\", NumberOfApprovalsNeeded: 1, ApprovalPoolMembers:[\"CodeCommitApprovers:123456789012:user/*\"]}]}}",
        "approvalRuleId": "aac33506-EXAMPLE",
        "originApprovalRuleTemplate": {},
        "creationDate": 1570752871.932,
        "lastModifiedDate": 1570754058.333,
        "approvalRuleName": Require two approved approvers",
        "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
        "ruleContentSha256": "cd93921cEXAMPLE",
    }
}
```
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[编辑或删除审批规则](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-edit-delete-pull-request-approval-rule.html#update-pull-request-approval-rule-content)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdatePullRequestApprovalRuleContent](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-pull-request-approval-rule-content.html)。

### `update-pull-request-approval-state`
<a name="codecommit_UpdatePullRequestApprovalState_cli_topic"></a>

以下代码示例演示了如何使用 `update-pull-request-approval-state`。

**AWS CLI**  
**批准或撤消对拉取请求的批准**  
以下 `update-pull-request-approval-state` 示例批准 ID 为 `27`、修订 ID 为 `9f29d167EXAMPLE` 的拉取请求。如果您想撤消批准，请将 `--approval-state` 参数值设置为 `REVOKE`。  

```
aws codecommit update-pull-request-approval-state \
    --pull-request-id 27  \
    --revision-id 9f29d167EXAMPLE  \
    --approval-state "APPROVE"
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS CodeCommit 用户指南》**中的[审查拉取请求](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-review-pull-request.html#update-pull-request-approval-state)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdatePullRequestApprovalState](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-pull-request-approval-state.html)。

### `update-pull-request-description`
<a name="codecommit_UpdatePullRequestDescription_cli_topic"></a>

以下代码示例演示了如何使用 `update-pull-request-description`。

**AWS CLI**  
**更改拉取请求的说明**  
此示例演示如何更改 ID 为 `47` 的拉取请求的说明。  

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

```
{
    "pullRequest": {
        "authorArn": "arn:aws:iam::111111111111:user/Li_Juan",
        "clientRequestToken": "",
        "creationDate": 1508530823.155,
        "description": "Updated the pull request to remove unused global variable.",
        "lastActivityDate": 1508372423.204,
        "pullRequestId": "47",
        "pullRequestStatus": "OPEN",
        "pullRequestTargets": [
            {
                "destinationCommit": "9f31c968EXAMPLE",
                "destinationReference": "refs/heads/main",
                "mergeMetadata": {
                    "isMerged": false,
                },
                "repositoryName": "MyDemoRepo",
                "sourceCommit": "99132ab0EXAMPLE",
                "sourceReference": "refs/heads/variables-branch"
            }
        ],
        "title": "Consolidation of global variables"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdatePullRequestDescription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-pull-request-description.html)。

### `update-pull-request-status`
<a name="codecommit_UpdatePullRequestStatus_cli_topic"></a>

以下代码示例演示了如何使用 `update-pull-request-status`。

**AWS CLI**  
**更改拉取请求的状态**  
此示例演示如何在名为 `MyDemoRepo` 的 AWS CodeCommit 存储库中将 ID 为 `42` 的拉取请求的状态更改为 `CLOSED` 的状态。  

```
aws codecommit update-pull-request-status \
    --pull-request-id 42 \
    --pull-request-status CLOSED
```
输出：  

```
{
    "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-approvers-needed-for-this-change",
                "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.165,
        "description": "Updated the pull request to remove unused global variable.",
        "lastActivityDate": 1508372423.12,
        "pullRequestId": "47",
        "pullRequestStatus": "CLOSED",
        "pullRequestTargets": [
            {
                "destinationCommit": "9f31c968EXAMPLE",
                "destinationReference": "refs/heads/main",
                "mergeMetadata": {
                    "isMerged": false,
                },
                "repositoryName": "MyDemoRepo",
                "sourceCommit": "99132ab0EXAMPLE",
                "sourceReference": "refs/heads/variables-branch"
            }
        ],
        "title": "Consolidation of global variables"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdatePullRequestStatus](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-pull-request-status.html)。

### `update-pull-request-title`
<a name="codecommit_UpdatePullRequestTitle_cli_topic"></a>

以下代码示例演示了如何使用 `update-pull-request-title`。

**AWS CLI**  
**更改拉取请求的标题**  
此示例演示如何更改 ID 为 `47` 的拉取请求的标题。  

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

```
{
    "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": "dd8b26gr-EXAMPLE",
                    "approvalRuleTemplateName": "2-approver-rule-for-main"
                },
                "ruleContentSha256": "4711b576EXAMPLE"
            }
        ],
        "authorArn": "arn:aws:iam::123456789012:user/Li_Juan",
        "clientRequestToken": "",
        "creationDate": 1508530823.12,
        "description": "Review the latest changes and updates to the global variables. I have updated this request with some changes, including removing some unused variables.",
        "lastActivityDate": 1508372657.188,
        "pullRequestId": "47",
        "pullRequestStatus": "OPEN",
        "pullRequestTargets": [
            {
                "destinationCommit": "9f31c968EXAMPLE",
                "destinationReference": "refs/heads/main",
                "mergeMetadata": {
                    "isMerged": false,
                },
                "repositoryName": "MyDemoRepo",
                "sourceCommit": "99132ab0EXAMPLE",
                "sourceReference": "refs/heads/variables-branch"
            }
        ],
        "title": "Consolidation of global variables - updated review"
    }
}
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdatePullRequestTitle](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-pull-request-title.html)。

### `update-repository-description`
<a name="codecommit_UpdateRepositoryDescription_cli_topic"></a>

以下代码示例演示了如何使用 `update-repository-description`。

**AWS CLI**  
**更改存储库的说明**  
此示例更改 AWS CodeCommit 存储库的说明。该命令只在出现错误时生成输出。  
命令:  

```
aws codecommit update-repository-description --repository-name MyDemoRepo --repository-description "This description was changed"
```
输出：  

```
None.
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateRepositoryDescription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-repository-description.html)。

### `update-repository-name`
<a name="codecommit_UpdateRepositoryName_cli_topic"></a>

以下代码示例演示了如何使用 `update-repository-name`。

**AWS CLI**  
**更改存储库的名称**  
此示例更改 AWS CodeCommit 存储库的名称。该命令只在出现错误时生成输出。更改 AWS CodeCommit 存储库的名称将更改用户连接到存储库所需的 SSH 和 HTTPS URL。在更新连接设置之前，用户无法连接到此存储库。此外，由于存储库的 ARN 会发生更改，更改存储库名称会使依赖该存储库 ARN 的所有 IAM 用户策略失效。  
命令:  

```
aws codecommit update-repository-name --old-name MyDemoRepo --new-name MyRenamedDemoRepo
```
输出：  

```
None.
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateRepositoryName](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-repository-name.html)。