如何从特定提交 ID 克隆存储库?

问题描述 投票:0回答:3

我正在尝试使用 HTTPs 克隆存储库 (sample.com/component.git),但来自特定的提交 ID。

我应该获取存储库,然后签出该提交 ID,最后克隆它,或者什么是更好的方法?

git fetch sample.com/component.git
git checkout 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff
git clone sample.com/component.git

或者

git clone sample.com/component.git 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff
git commit git-clone
3个回答
11
投票

尝试这 3 个步骤,

第 1 步:克隆主存储库:

git clone sample.com/component.git

进入克隆的存储库

cd folder_name
。现在您已经有了一个提取了最新版本的工作目录,并且您想移回特定的提交 ID,具体操作方法如下:

第2步:

git reset --hard 9a36b9e79tbb9132c7 #(takes you back to that commit)

步骤3:

git clean -df #(cleans any untracked files/folders)

0
投票

基于 Aurélien Gâteau 评论的替代答案。

git clone sample.com/component.git
cd component
git checkout 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff

假设项目文件夹名称为

component


0
投票

我想分享一个围绕这个问题找到的非常简洁的解决方案

查看: https://graphite.dev/guides/git-clone-specific-commit

总结:

mkdir <repo-name>
cd <repo-name>
git init
git remote add origin <repository-url>
git fetch origin <commit-hash>
git checkout FETCH_HEAD
© www.soinside.com 2019 - 2024. All rights reserved.