将GitHub存储库复制到CodeCommit中

这是我在Qiita上的首次投稿。

在尝试验证AWS Amplify时,我之前可以从示例中创建项目,但不知何时示例消失了。我在GitHub上找到了归档,为了以防万一,我将其复制到了CodeCommit。以下是该过程的步骤备忘录。

另外,此示例是以下内容:
https://github.com/aws-samples/aws-amplify-appsync-graphql-real-time-canvas

索引

    • CodeCommitのレポジトリを作成

 

    • GitHubからクローン(ベアコピー)を作成

 

    • CodeCommitにpush

 

    • ベアコピーしたレポジトリを削除

 

    • 動作確認

 

    (おまけ)codecommitのデフォルトブランチを変更

创建CodeCommit存储库

首先,我们将创建一个CodeCommit的仓库。
具体步骤请参考以下官方手册:
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/how-to-create-repository.html

这次我们是通过AWS CLI从Cloud9上创建的。

aws codecommit create-repository \
--repository-name aws-amplify-appsync-graphql-real-time-canvas \
--repository-description "aws-amplify-appsync-graphql-real-time-canvas" \
--tags Category=aws-samples

执行结果如下:请记下”cloneUrlHttp”的值。
※克隆URL可以通过AWS CLI或AWS控制台进行确认。

$ aws codecommit create-repository \
> --repository-name aws-amplify-appsync-graphql-real-time-canvas \
> --repository-description "aws-amplify-appsync-graphql-real-time-canvas" \
> --tags Category=aws-samples
{
    "repositoryMetadata": {
        "repositoryName": "aws-amplify-appsync-graphql-real-time-canvas", 
        "cloneUrlSsh": "ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas", 
        "lastModifiedDate": 1674977236.362, 
        "repositoryDescription": "aws-amplify-appsync-graphql-real-time-canvas", 
        "cloneUrlHttp": "https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas", 
        以下省略
    }
}

从GitHub上克隆(创建裸拷贝)。

接下来,我们使用git的”–mirror”选项,从GitHub克隆到本地(在这里是Cloud9)。
详细信息请参考以下官方手册:
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/how-to-migrate-repository-existing.html

指令如下所示。

git clone --mirror \
https://github.com/aws-samples/aws-amplify-appsync-graphql-real-time-canvas \
aws-amplify-appsync-graphql-real-time-canvas

执行结果如下所示。

$ git clone --mirror \
> https://github.com/aws-samples/aws-amplify-appsync-graphql-real-time-canvas \
> aws-amplify-appsync-graphql-real-time-canvas
Cloning into bare repository 'aws-amplify-appsync-graphql-real-time-canvas'...
remote: Enumerating objects: 533, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 533 (delta 23), reused 35 (delta 14), pack-reused 487
Receiving objects: 100% (533/533), 32.10 MiB | 21.71 MiB/s, done.
Resolving deltas: 100% (313/313), done.

将代码推送到CodeCommit

接下来,我们将把克隆仓库推送到事先创建的CodeCommit仓库中。
推送目标是在创建CodeCommit仓库时记录的克隆URL。
命令如下所示:

git push \
https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas \
--all

执行结果如下:

$ cd aws-amplify-appsync-graphql-real-time-canvas/
(BARE:master) $ git push \
> https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas \
> --all
Enumerating objects: 293, done.
Counting objects: 100% (293/293), done.
Compressing objects: 100% (139/139), done.
Writing objects: 100% (293/293), 28.18 MiB | 33.25 MiB/s, done.
Total 293 (delta 153), reused 289 (delta 150), pack-reused 0
remote: Validating objects: 100%
To https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas
 * [new branch]      bradruof/FixVulnerability -> bradruof/FixVulnerability
 * [new branch]      fix/security-patch-immer -> fix/security-patch-immer
 * [new branch]      master -> master
 * [new branch]      nimacks-patch-1 -> nimacks-patch-1
 * [new branch]      nimacks-patch-2 -> nimacks-patch-2
 * [new branch]      nimacks-patch-3 -> nimacks-patch-3
 * [new branch]      security-patch/node-forge -> security-patch/node-forge
 * [new branch]      swaminator-patch-1 -> swaminator-patch-1

删除克隆的存储库。

无法使用克隆的存储库如下所示。

(BARE:master) $ git checkout bradruof/FixVulnerability
fatal: this operation must be run in a work tree

我会删除。

(BARE:master) $ cd ..
$ rm -fr aws-amplify-appsync-graphql-real-time-canvas

确认操作

接下来,您只需像往常一样使用代码库即可。以下是一个示例。

我想要确认一下我在 CodeCommit 上 push 的仓库的分支。

$ aws codecommit list-branches \
> --repository-name aws-amplify-appsync-graphql-real-time-canvas
{
    "branches": [
        "fix/security-patch-immer", 
        "master", 
        "nimacks-patch-1", 
        "security-patch/node-forge", 
        "swaminator-patch-1", 
        "nimacks-patch-2", 
        "nimacks-patch-3", 
        "bradruof/FixVulnerability"
    ]
}

如果您不知道CodeCommit仓库的克隆URL,您可以按照以下方式进行确认。

$ aws codecommit get-repository --repository-name aws-amplify-appsync-graphql-real-time-canvas
{
    "repositoryMetadata": {
        "creationDate": 1674977236.362, 
        "defaultBranch": "bradruof/FixVulnerability", 
        "repositoryName": "aws-amplify-appsync-graphql-real-time-canvas", 
        "cloneUrlSsh": "ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas", 
        "lastModifiedDate": 1674977941.396, 
        "repositoryDescription": "aws-amplify-appsync-graphql-real-time-canvas", 
        "cloneUrlHttp": "https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas", 
        以下省略
    }
}

将CodeCommit的存储库克隆到本地。

$ git clone \
> https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/aws-amplify-appsync-graphql-real-time-canvas \
> -b bradruof/FixVulnerability
Cloning into 'aws-amplify-appsync-graphql-real-time-canvas'...
remote: Counting objects: 293, done.
Receiving objects: 100% (293/293), 28.18 MiB | 10.91 MiB/s, done.
Resolving deltas: 100% (153/153), done.

以下是正常克隆的确认信息。

$ cd aws-amplify-appsync-graphql-real-time-canvas/
(bradruof/FixVulnerability) $ ls
amplify  CODE_OF_CONDUCT.md  CONTRIBUTING.md  graphqlgif1.gif  LICENSE  package.json  package-lock.json  public  README.md  src

在中国有一个选项,可以用中文本地化地转述以下内容:CodeCommit的命令参考可以在CodeCommit的官方手册中找到。

 

关于基本的Git命令,CodeCommit的官方手册中也有相关说明。

 

CodeCommit的官方手册非常易懂好用。

更改CodeCommit的默认分支 (Change the default branch of CodeCommit)

这是一个附加信息,关于如何更改CodeCommit的默认分支。
似乎可以直接通过AWS控制台来完成。(我之前不知道这个功能)

 

广告
将在 10 秒后关闭
bannerAds