特定のリビジョンでgitリポジトリのクローンを作成する
この投稿では、特定のリビジョンでgitリポジトリのクローンを作成する方法について説明します。
1.gitフェッチ
Gitリポジトリの特定のリビジョンのクローンを作成するには、回避するのが最善です git-clone git-cloneは完全なリポジトリのクローンを作成するためです。推奨される解決策は、クローンを作成する特定のブランチをフェッチすることです。 git-fetch
。完全な手順は次のとおりです。
# create and initialize an empty repository
git init
# add a remote named origin for the repository at <repository>
git remote add origin <repository>
# fetch a commit using its hash
git fetch origin <commit-hash>
# reset repository to that commit
git reset --hard FETCH_HEAD
git init
# add a remote named origin for the repository at <repository>
git remote add origin <repository>
# fetch a commit using its hash
git fetch origin <commit-hash>
# reset repository to that commit
git reset --hard FETCH_HEAD
このアプローチを以下に示します。
2.gitクローン
小規模なリポジトリの場合は、 git-clone
リポジトリを特定のコミットに簡単にリセットするには git-reset、以下に示すように:
# clone the git repository into the current directory
git clone <repository> .
# hard reset repository to a specific commit
git reset --hard <commit-hash>
git clone <repository> .
# hard reset repository to a specific commit
git reset --hard <commit-hash>
これは、マスターブランチにいることを前提としています。再び最新のコミットに戻るには、単純に次のことを実行できます git-pull
。これを以下に示します。
または、実行することもできます git-clone
次に、特定のリビジョンをチェックアウトします git-checkout.
# clone the git repository into the current directory
git clone <repository> .
# checkout a commit using its hash
git checkout <commit-hash>
# hard reset repository
git reset --hard
git clone <repository> .
# checkout a commit using its hash
git checkout <commit-hash>
# hard reset repository
git reset --hard
このアプローチを以下に示します。
これで、特定のリビジョンのGitリポジトリのクローンを作成できます。