

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在中查看提交详情 AWS CodeCommit
<a name="how-to-view-commit-details"></a>

您可以使用 AWS CodeCommit 控制台浏览仓库中的提交历史记录。这可以帮助您确定在存储库中进行的更改，包括：
+ 做出更改的时间和更改者。
+ 特定提交合并到一个分支的时间。

查看分支的提交历史记录也许可帮助您了解分支之间的差异。如果您使用了标记，还可以快速查看带有标签的提交及该提交的父级。在命令行中，您可以使用 Git 查看有关本地存储库或仓 CodeCommit 库中提交的详细信息。

## 浏览存储库中的提交
<a name="how-to-view-commit-details-console"></a>

您可以使用 AWS CodeCommit 控制台浏览仓库的提交历史记录。您还可以按时间顺序查看存储库及其分支中提交的图表。这可以帮助您了解存储库的历史记录，包括做出更改的时间。

**注意**  
使用 **git rebase** 命令对存储库执行变基操作会更改存储库的历史记录，这可能会导致提交出现乱序。有关更多信息，请参阅 [Git Branching-Rebasing](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) 或 Git 文档。

**Topics**
+ [浏览存储库的提交历史记录](#how-to-view-commit-details-console-history)
+ [查看存储库的提交历史记录图表](#how-to-view-commit-details-console-visualizer)

### 浏览存储库的提交历史记录
<a name="how-to-view-commit-details-console-history"></a>

您可以浏览存储库特定分支或标签的提交历史记录，包括有关提交者和提交消息的信息。您也可以查看提交的代码。

**浏览提交历史记录**

1. 在 [https://console.aws.amazon.com/codesuite/codemmit](https://console.aws.amazon.com/codesuite/codecommit/home) /home 打开 CodeCommit 控制台。

1. 在 **Repositories (存储库)**中，选择要查看其提交历史记录的存储库。

1. 在导航窗格中，选择 **Commits**。在提交历史记录视图中，系统按提交日期的反向时间顺序显示存储库默认分支中的提交的历史记录。日期和时间用协调世界时 (UTC) 表示。您可以按照如下方式查看不同分支的提交历史记录：选择视图选择器按钮，然后从列表中选择分支。如果您在存储库中使用了标签，则可通过在视图选择器按钮中选择特定标签来查看具有该标签的提交及其父级。  
![\[控制台中的提交视图\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-commit-list.png)

1. 要查看提交与其父项之间的差异并查看对更改的评论，请选择缩写的提交 ID。有关更多信息，请参阅[比较提交与其父级](how-to-compare-commits.md#how-to-compare-commits-parent)和[评论提交](how-to-commit-comment.md)。要查看提交及分支、标签或提交 ID 等任何其他提交说明符之间的差异，请参阅[比较任意两个提交说明符](how-to-compare-commits.md#how-to-compare-commits-compare)。

1. 执行以下一个或多个操作：
   + 要查看进行更改的日期和时间，请将鼠标指针悬停在提交日期上方。
   + 要查看完整的提交 ID，请复制然后将其粘贴到文本编辑器或其他位置。要复制它，请选择 **Copy ID (复制 ID)**。
   + 要查看提交时的代码，请选择 **Browse (浏览)**。**Code** 视图中显示做出该提交时存储库中的内容。视图选择器按钮显示缩写的提交 ID，而不是分支或标签。

### 查看存储库的提交历史记录图表
<a name="how-to-view-commit-details-console-visualizer"></a>

您可以查看对存储库做出的提交的图表。**Commit Visualizer** 视图是一个有向无环图 (DAG)，它表示对存储库的某个分支做出的所有提交。该图形表示可以帮助您了解添加或合并提交及相关功能的时间。它还能帮助您确定某项更改相对其他更改的执行时间。

**注意**  
在提交图表中，使用快速转发方法合并的提交不会以单独的行显示。

**查看提交图表**

1. 在 [https://console.aws.amazon.com/codesuite/codemmit](https://console.aws.amazon.com/codesuite/codecommit/home) /home 打开 CodeCommit 控制台。

1. 在 **Repositories (存储库)**中，选择要查看其提交图表的存储库。

1. 在导航窗格中，选择 **Commits (提交)**，然后选择 **Commit visualizer (提交可视化工具)** 选项卡。  
![\[控制台中的存储库图形视图\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-cv-complex1.png)

   在提交图表中，每个提交消息的缩写提交 ID 和主题都显示在图表中所示点的旁边。
**注意**  
图表在一页上最多可显示 35 个分支。如果分支数超过 35 个，图表会变得太过复杂而无法显示。您可通过以下两种方法简化视图：  
使用视图选择器按钮显示特定分支的图表。
将完整的提交 ID 粘贴到搜索框中以呈现该提交的图表。

1. 要呈现提交的新图表，请从图表中选择与该提交对应的点。视图选择器按钮更改为缩写的提交 ID。  
![\[呈现的特定提交的新图表\]](http://docs.aws.amazon.com/zh_cn/codecommit/latest/userguide/images/codecommit-cv-commit.png)

## 查看提交详细信息 (AWS CLI)
<a name="how-to-view-commit-details-cli"></a>

Git 可让您查看提交的详细信息。您还可以通过运行以下命令 AWS CLI 来查看有关本地存储库或 CodeCommit 存储库中提交的详细信息：
+ 要查看有关提交的信息，请运行 **[aws codecommit get-commit](#how-to-view-commit-details-cli-commit)**。
+ 要查看有关多个提交的信息，请运行 **[aws codecommit batch-get-commits](#how-to-view-commit-details-cli-batch-get-commits)**。
+ 要查看有关合并提交的信息，请运行 **[aws codecommit get-merge-commit](#how-to-view-commit-details-cli-merge-commit)**。
+ 要查看有关提交说明符（分支、标记、HEAD 或其他完全限定引用，例如提交 IDs）的更改信息，请运行**[aws codecommit get-differences](#how-to-view-commit-details-cli-differences)**。
+ 要查看存储库中单个 Git blob 对象的 base64 编码内容，请运行 **[aws codecommit get-blob](#how-to-view-commit-details-cli-blob)**。

### 查看有关提交的信息
<a name="how-to-view-commit-details-cli-commit"></a>

1. 运行 **aws codecommit get-commit** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + 完整的提交 ID。

   例如，要在名为`MyDemoRepo`：的 CodeCommit 存储库`317f8570EXAMPLE`中查看 ID 为的提交的信息：

   ```
   aws codecommit get-commit  --repository-name MyDemoRepo  --commit-id 317f8570EXAMPLE 
   ```

1. 如果成功，该命令的输出包括以下内容：
   + 有关提交作者的信息（如 Git 中所配置），包括时间戳格式的日期和协调世界时 (UTC) 偏移量。
   + 有关提交者的信息（如 Git 中所配置），包括时间戳格式的日期和 UTC 偏移量。
   + 提交所在的 Git 树的 ID。
   + 父提交的提交 ID。
   + 提交消息。

   下面是前面示例命令的一些示例输出：

   ```
   {
       "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": "347a3408EXAMPLE",
           "parents": [
               "4c925148EXAMPLE"
           ],
           "message": "Fix incorrect variable name"
       }
   }
   ```

### 查看有关合并提交的信息
<a name="how-to-view-commit-details-cli-merge-commit"></a>

1. 运行 **get-merge-commit** 命令，并指定：
   + 合并源的提交说明符（使用 **--source-commit-specifier** 选项）。
   + 合并目标的提交说明符（使用 **--destination-commit-specifier** 选项）。
   + 要使用的合并选项（使用 **--merge-option** 选项）。
   + 存储库的名称（使用 **--repository-name** 选项）。

   例如，要在名为的存储库中查看有关源分支*bugfix-bug1234*的合并提交的信息，目标分支*main*使用*THREE\$1WAY\$1MERGE*策略命名*MyDemoRepo*：

   ```
   aws codecommit get-merge-commit --source-commit-specifier bugfix-bug1234 --destination-commit-specifier main --merge-option THREE_WAY_MERGE --repository-name MyDemoRepo
   ```

1. 如果成功，该命令的输出返回类似以下内容的信息：

   ```
   {
       "sourceCommitId": "c5709475EXAMPLE", 
       "destinationCommitId": "317f8570EXAMPLE", 
       "baseCommitId": "fb12a539EXAMPLE",
       "mergeCommitId": "ffc4d608eEXAMPLE"
   }
   ```

### 查看有关多个提交的信息
<a name="how-to-view-commit-details-cli-batch-get-commits"></a>

1. 运行 **batch-get-commits** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + 要查看其 IDs 信息的每个提交的完整提交列表。

   例如，要在名为`MyDemoRepo`：的 CodeCommit 存储库`4c925148EXAMPLE`中查看有关使用 IDs`317f8570EXAMPLE`和的提交的信息：

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

1. 如果成功，该命令的输出包括以下内容：
   + 有关提交作者的信息（如 Git 中所配置），包括时间戳格式的日期和协调世界时 (UTC) 偏移量。
   + 有关提交者的信息（如 Git 中所配置），包括时间戳格式的日期和 UTC 偏移量。
   + 存在提交 IDs 的 Git 树中的。
   + 父 IDs 提交的提交。
   + 提交消息。

   下面是前面示例命令的一些示例输出：

   ```
   {
       "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"
       }   
   }
   ```

### 查看提交说明符更改的相关信息
<a name="how-to-view-commit-details-cli-differences"></a>

1. 运行 **aws codecommit get-differences** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + 要获取其信息的提交说明符。只有 `--after-commit-specifier` 是必需的。如果未指定 `--before-commit-specifier`，则显示自 `--after-commit-specifier` 起当前的所有文件。

   例如，要在名为`MyDemoRepo`：的 CodeCommit 存储库`4c925148EXAMPLE`中查看有关使用 IDs`317f8570EXAMPLE`和的提交之间的区别的信息：

   ```
   aws codecommit get-differences  --repository-name MyDemoRepo  --before-commit-specifier 317f8570EXAMPLE --after-commit-specifier 4c925148EXAMPLE
   ```

1. 如果成功，该命令的输出包括以下内容：
   + 差异列表，包括更改类型 (A 表示已添加、D 表示已删除、M 表示已修改)。
   + 文件更改类型的模式。
   + 包含更改的 Git blob 对象的 ID。

   下面是前面示例命令的一些示例输出：

   ```
   {
       "differences": [
           {
               "afterBlob": {
                   "path": "blob.txt",
                   "blobId": "2eb4af3bEXAMPLE",
                   "mode": "100644"
               },
               "changeType": "M",
               "beforeBlob": {
                   "path": "blob.txt",
                   "blobId": "bf7fcf28fEXAMPLE",
                   "mode": "100644"
               }
           }
       ]
   }
   ```

### 查看有关 Git blob 对象的信息
<a name="how-to-view-commit-details-cli-blob"></a>

1. 运行 **aws codecommit get-blob** 命令，并指定：
   +  CodeCommit 存储库的名称（带`--repository-name`选项）。
   + Git Blob 的 ID（使用 `--blob-id ` 选项）。

   例如，要在名`MyDemoRepo`为的 CodeCommit 仓库`2eb4af3bEXAMPLE`中查看 ID 为的 Git blob 的信息：

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

1. 如果成功，该命令的输出包括以下内容：
   + blob 的 base64 编码内容，通常是一个文件。

   例如，上一个命令的输出可能类似于以下内容：

   ```
   {
       "content": "QSBCaW5hcnkgTGFyToEXAMPLE="
   }
   ```

## 查看提交详细信息 (Git)
<a name="how-to-view-commit-details-git"></a>

在执行这些步骤之前，您应该已经将本地存储库连接到 CodeCommit 存储库并提交了更改。有关说明，请参阅[连接存储库](how-to-connect.md)。

要显示到存储库的最新提交的更改，请运行 **git show** 命令。

```
git show
```

该命令生成类似于下述信息的输出：

```
commit 4f8c6f9d
Author: Mary Major <mary.major@example.com>
Date:   Mon May 23 15:56:48 2016 -0700

    Added bumblebee.txt

diff --git a/bumblebee.txt b/bumblebee.txt
new file mode 100644
index 0000000..443b974
--- /dev/null
+++ b/bumblebee.txt
@@ -0,0 +1 @@
+A bumblebee, also written bumble bee, is a member of the bee genus Bombus, in the family Apidae.
\ No newline at end of file
```

**注意**  
在本示例和以下示例中，commit IDs 被缩写了。未显示完整的提交 IDs 。

要查看发生的更改，请使用 **git show** 命令并指定提交 ID：

```
git show 94ba1e60

commit 94ba1e60
Author: John Doe <johndoe@example.com>
Date:   Mon May 23 15:39:14 2016 -0700

    Added horse.txt

diff --git a/horse.txt b/horse.txt
new file mode 100644
index 0000000..080f68f
--- /dev/null
+++ b/horse.txt
@@ -0,0 +1 @@
+The horse (Equus ferus caballus) is one of two extant subspecies of Equus ferus.
```

要查看两次提交之间的区别，请运行**git diff**命令并包含两个提交 IDs。

```
git diff ce22850d 4f8c6f9d
```

在本例中，两个提交之间的差异是添加了两个文件。该命令生成类似于下述信息的输出：

```
diff --git a/bees.txt b/bees.txt
new file mode 100644
index 0000000..cf57550
--- /dev/null
+++ b/bees.txt
@@ -0,0 +1 @@
+Bees are flying insects closely related to wasps and ants, and are known for their role in pollination and for producing honey and beeswax.
diff --git a/bumblebee.txt b/bumblebee.txt
new file mode 100644
index 0000000..443b974
--- /dev/null
+++ b/bumblebee.txt
@@ -0,0 +1 @@
+A bumblebee, also written bumble bee, is a member of the bee genus Bombus, in the family Apidae.
\ No newline at end of file
```

要使用 Git 查看有关本地存储库中的提交的详细信息，请运行 **git log** 命令：

```
git log
```

如果成功，该命令产生类似以下内容的输出：

```
commit 94ba1e60
Author: John Doe <johndoe@example.com>
Date:   Mon May 23 15:39:14 2016 -0700

    Added horse.txt

commit 4c925148
Author: Jane Doe <janedoe@example.com>
Date:   Mon May 22 14:54:55 2014 -0700

    Added cat.txt and dog.txt
```

要仅显示提交 IDs 和消息，请运行以下**git log --pretty=oneline**命令：

```
git log --pretty=oneline
```

如果成功，该命令产生类似以下内容的输出：

```
94ba1e60 Added horse.txt
4c925148 Added cat.txt and dog.txt
```

有关更多选项，请参阅 Git 文档。