

第 5 版 (V5) AWS Tools for PowerShell 已發行！

如需有關中斷變更和遷移應用程式的資訊，請參閱[遷移主題](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Tools for PowerShell V5 的 CodeCommit 範例
<a name="powershell_codecommit_code_examples"></a>

下列程式碼範例示範如何使用 AWS Tools for PowerShell V5 搭配 CodeCommit 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `Get-CCBranch`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定儲存庫之指定分支的相關資訊。**  

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

```
BranchName                              CommitId
----------                              --------
MyNewBranch                             7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CCBranchList`。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定儲存庫的分支名稱清單。**  

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

```
master
MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListBranches](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CCRepository`。

**Tools for 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 參考 (V5)》**中的 [GetRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CCRepositoryBatch`。

**Tools for PowerShell V5**  
**範例 1：此範例確認哪些指定的儲存庫可找到和找不到。**  

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

```
Repositories                            RepositoriesNotFound
------------                            --------------------
{MyDemoRepo, MyNewRepo}                {AMissingRepo}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [BatchGetRepositories](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-CCRepositoryList`。

**Tools for 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 參考 (V5)》**中的 [ListRepositories](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CCBranch`。

**Tools for PowerShell V5**  
**範例 1：此範例會建立具有指定儲存庫之指定名稱，以及指定遞交 ID 的新分支。**  

```
New-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch -CommitId 7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-CCRepository`。

**Tools for 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 參考 (V5)》**中的 [CreateRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Remove-CCRepository`。

**Tools for PowerShell V5**  
**範例 1：此範例強制刪除指定的儲存庫。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除儲存庫，無需提示。**  

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

```
43ef2443-3372-4b12-9e78-65c27EXAMPLE
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [DeleteRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Update-CCDefaultBranch`。

**Tools for PowerShell V5**  
**範例 1：此範例將指定的儲存庫的預設分支變更為指定的分支。**  

```
Update-CCDefaultBranch -RepositoryName MyDemoRepo -DefaultBranchName MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateDefaultBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Update-CCRepositoryDescription`。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定之儲存庫的描述。**  

```
Update-CCRepositoryDescription -RepositoryName MyDemoRepo -RepositoryDescription "This is an updated description."
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateRepositoryDescription](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Update-CCRepositoryName`。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定之儲存庫的名稱。**  

```
Update-CCRepositoryName -NewName MyDemoRepo2 -OldName MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateRepositoryName](https://docs.aws.amazon.com/powershell/v5/reference)。