我正在尝试使用 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
尝试这 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)
基于 Aurélien Gâteau 评论的替代答案。
git clone sample.com/component.git
cd component
git checkout 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff
假设项目文件夹名称为
component
。
我想分享一个围绕这个问题找到的非常简洁的解决方案
查看: 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