[英]git shallow clone *several* specific refs (commits), *which are not branches*
For my specific use case, I only need a shallow git clone that contains just two specific commits, and nothing else (no remaining history, no other branches).对于我的特定用例,我只需要一个浅的 git 克隆,它只包含两个特定的提交,没有其他内容(没有剩余的历史记录,没有其他分支)。
Here are some things I tried:以下是我尝试过的一些事情:
git clone --single-branch --branch BRANCHNAME
is not good, because that fetches only one branchgit clone --single-branch --branch BRANCHNAME
不好,因为它只获取一个分支4ebbd7cc6
and fc139d960
), which is another reason why git clone --single-branch --branch BRANCHNAME
is not good.4ebbd7cc6
和fc139d960
),这是git clone --single-branch --branch BRANCHNAME
的另一个原因。git clone --depth N --no-single-branch
is not good, as it will fetch all the branches and tags that I don't need, and I can't know anyway what a good N
could be, so that I would overfetch anyway even if there were no branches and tags.git clone --depth N --no-single-branch
不好,因为它会获取我不需要的所有分支和标签,而且我不知道什么是好的N
,所以即使没有分支和标签,我也会过度获取。 What's the correct way to fetch exactly n commits and nothing else ?准确获取n 次提交的正确方法是什么?
Instead of cloning, the solution is to init an empty git repo, and fetch each ref one-by-one with --depth 1
:解决方案不是克隆,而是初始化一个空的 git 存储库,并使用
--depth 1
逐个获取每个引用:
mkdir FOLDER_NAME
cd FOLDER_NAME
git init
git remote add origin GIT_URL
git fetch --depth 1 origin REF1
git fetch --depth 1 origin REF2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.