简体   繁体   English

git 浅层克隆 *几个*特定的参考(提交),*不是分支*

[英]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:以下是我尝试过的一些事情:

  • I want to fetch two refs, hence git clone --single-branch --branch BRANCHNAME is not good, because that fetches only one branch我想获取两个参考,因此git clone --single-branch --branch BRANCHNAME不好,因为它只获取一个分支
  • I want to fetch refs which are not branch names (say, 4ebbd7cc6 and fc139d960 ), which is another reason why git clone --single-branch --branch BRANCHNAME is not good.我想获取不是分支名称的引用(例如4ebbd7cc6fc139d960 ),这是git clone --single-branch --branch BRANCHNAME的另一个原因。
  • I want truly minimal history.我想要真正最小的历史。 Just those two commits and nothing else.只有这两个提交,没有别的。 There can be any arbitrarily long git history between those two commits, and there are hundreds of branches.这两个提交之间可以有任意长的 git 历史,并且有数百个分支。 Hence doing 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM