

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# CodeCommit 使用适用于 PowerShell V5 的工具的示例
<a name="powershell_5_codecommit_code_examples"></a>

以下代码示例向您展示了如何使用带 CodeCommit的 AWS Tools for PowerShell V5 来执行操作和实现常见场景。

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

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

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

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

### `Get-CCBranch`
<a name="codecommit_GetBranch_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Get-CCBranch`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取有关指定存储库的指定分支的信息。**  

```
Get-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch
```
**输出**：  

```
BranchName                              CommitId
----------                              --------
MyNewBranch                             7763222d...561fc9c9
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetBranch](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-CCBranchList`
<a name="codecommit_ListBranches_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Get-CCBranchList`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定存储库的分支名称的列表。**  

```
Get-CCBranchList -RepositoryName MyDemoRepo
```
**输出**：  

```
master
MyNewBranch
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListBranches](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-CCRepository`
<a name="codecommit_GetRepository_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Get-CCRepository`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例获取指定存储库的信息。**  

```
Get-CCRepository -RepositoryName MyDemoRepo
```
**输出**：  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/8/2015 3:21:33 PM
DefaultBranch         :
LastModifiedDate      : 9/8/2015 3:21:33 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE
RepositoryName        : MyDemoRepo
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetRepository](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-CCRepositoryBatch`
<a name="codecommit_BatchGetRepositories_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Get-CCRepositoryBatch`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例确认已找到和未找到哪些指定的存储库。**  

```
Get-CCRepositoryBatch -RepositoryName MyDemoRepo, MyNewRepo, AMissingRepo
```
**输出**：  

```
Repositories                            RepositoriesNotFound
------------                            --------------------
{MyDemoRepo, MyNewRepo}                {AMissingRepo}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [BatchGetRepositories](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-CCRepositoryList`
<a name="codecommit_ListRepositories_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Get-CCRepositoryList`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例按存储库名称的升序列出所有存储库。**  

```
Get-CCRepositoryList -Order Ascending -SortBy RepositoryName
```
**输出**：  

```
RepositoryId                            RepositoryName
------------                            --------------
c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE    MyDemoRepo
05f30c66-e3e3-4f91-a0cd-1c84aEXAMPLE    MyNewRepo
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListRepositories](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-CCBranch`
<a name="codecommit_CreateBranch_powershell_5_topic"></a>

以下代码示例演示了如何使用 `New-CCBranch`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定存储库的指定名称和指定的提交 ID 创建一个新分支。**  

```
New-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch -CommitId 7763222d...561fc9c9
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateBranch](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-CCRepository`
<a name="codecommit_CreateRepository_powershell_5_topic"></a>

以下代码示例演示了如何使用 `New-CCRepository`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例使用指定的名称和指定的描述创建新的存储库。**  

```
New-CCRepository -RepositoryName MyDemoRepo -RepositoryDescription "This is a repository for demonstration purposes."
```
**输出**：  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/18/2015 4:13:25 PM
DefaultBranch         :
LastModifiedDate      : 9/18/2015 4:13:25 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : 43ef2443-3372-4b12-9e78-65c27EXAMPLE
RepositoryName        : MyDemoRepo
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateRepository](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-CCRepository`
<a name="codecommit_DeleteRepository_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Remove-CCRepository`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例强制删除指定的存储库。在继续操作之前，该命令将提示进行确认。添加 -Force 参数可在不提示的情况下删除存储库。**  

```
Remove-CCRepository -RepositoryName MyDemoRepo
```
**输出**：  

```
43ef2443-3372-4b12-9e78-65c27EXAMPLE
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteRepository](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-CCDefaultBranch`
<a name="codecommit_UpdateDefaultBranch_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Update-CCDefaultBranch`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定存储库的默认分支更改为指定的分支。**  

```
Update-CCDefaultBranch -RepositoryName MyDemoRepo -DefaultBranchName MyNewBranch
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateDefaultBranch](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-CCRepositoryDescription`
<a name="codecommit_UpdateRepositoryDescription_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Update-CCRepositoryDescription`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例更改指定存储库的描述。**  

```
Update-CCRepositoryDescription -RepositoryName MyDemoRepo -RepositoryDescription "This is an updated description."
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateRepositoryDescription](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-CCRepositoryName`
<a name="codecommit_UpdateRepositoryName_powershell_5_topic"></a>

以下代码示例演示了如何使用 `Update-CCRepositoryName`。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例更改指定存储库的名称。**  

```
Update-CCRepositoryName -NewName MyDemoRepo2 -OldName MyDemoRepo
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateRepositoryName](https://docs.aws.amazon.com/powershell/v5/reference)中的。