我想创建没有使用clone的标签的裸git项目。但是通过Google知道没有像“--no-tags
”这样的选项。
有没有办法克隆没有像下面这样的标签?
$ git clone {path}/test.git --no-tags --mirror
任何帮助将不胜感激! :)
答案 0 :(得分:9)
我也通过一些小道和谷歌搜索。
我使用以下步骤制作它。
1)初始化一个裸仓库:
mkdir project
cd project
git init --bare
2)添加遥控器并为其配置正确的refspec:
git remote add origin <REPO_URL>
git config remote.origin.fetch +refs/heads/*:refs/heads/*
git config remote.origin.tagopt --no-tags
3)获取数据:
git remote update origin
如果您希望在第一次提取时省略标记,则省略 设置remote..tagopt变量并使用
git fetch --no-tags
用于获取数据。注意下次获取没有 &#34; - 无标记&#34;除非你设置了,否则将获取自动获取标签 之前是remote..tagopt配置选项。
答案 1 :(得分:6)
使用Git 2.13.x / 2.14(2017年第二季度),这是可能的(即:克隆没有标签)
recodqual()见commit 1524ccd,commit 0dab246,commit 28d67d9(2017年4月26日)。{
(2017年5月16日Ævar Arnfjörð Bjarmason (avar
) Junio C Hamano -- gitster
--合并)
clone
:添加--no-tags
选项以克隆无标签添加
--no-tags
选项进行克隆而不提取任何标记。如果没有这种改变,没有简单的方法来克隆存储库 还提取其标签。
当提供
--single-branch
时,将克隆主要远程分支,但此外还将遵循标记&amp;检索。
现在--no-tags
可以添加--single-branch
来克隆存储库 标签,仅跟踪单个上游分支。此选项也可以在没有
--single-branch
的情况下运行,并且会执行此操作 普通克隆但不获取任何标签。许多git命令根据引用数量支付一些固定开销。例如。在
linux.git
中创建~40k标签将导致像git log -1 >/dev/null
这样的命令在一秒钟内运行而不是在几毫秒内运行,此外还会有许多其他因素会减慢,例如使用bash完成的“git log <TAB>
”将慢慢显示~40k引用而不是1。用户可能希望避免所有这些开销,只需使用这样的存储库来浏览“主”分支,或者像CI工具这样的东西可能希望保持一个分支是最新的关心任何其他参考文献。
如果没有这种改变,实现这一目标的唯一方法就是通过 在新的存储库中手动调整配置:
git init git && cat >git/.git/config <<EOF && [remote "origin"] url = git@github.com:git/git.git tagOpt = --no-tags fetch = +refs/heads/master:refs/remotes/origin/master [branch "master"] remote = origin merge = refs/heads/master EOF cd git && git pull
这需要硬编码“
master
”名称,这可能不是主要名称--single-branch
可以检索,或者通过设置检索 克隆后立即tagOpt=--no-tags
删除任何现有标签:git clone --single-branch git@github.com:git/git.git && cd git && git config remote.origin.tagOpt --no-tags && git tag -l | xargs git tag -d
当
--branch
被指向a时,当然还有巧妙的错误 标记,将用户留在分离的头部:git clone --single-branch --branch v2.12.0 git@github.com:git/git.git && cd git && git config remote.origin.tagOpt --no-tags && git tag -l | xargs git tag -d
现在所有这些复杂性变得更加简单:
git clone --single-branch --no-tags git@github.com:git/git.git
或者在克隆单个标签“branch”的情况下:
git clone --single-branch --branch v2.12.0 --no-tags git@github.com:git/git.git
答案 2 :(得分:0)
“镜子”意味着“标签”:如果没有后者,你就不能拥有前者。
从根本上说,--mirror
表示:
refs/*:refs/*
由于代码位于refs/tags/
,因此上面的第二个项目符号表示会复制代码。
为避免复制标记,您需要一组不同的refspec。选择您希望复制的那个(例如refs/heads/*
和refs/notes/*
)并在裸克隆中明确列出。 (您可以先创建一个完整的--mirror
克隆,然后编辑配置文件并删除任何不需要的已经复制的引用。)
您可能还想将remote.name.tagopt
设置为--no-tags
以禁用自动“匹配标记”提取。
答案 3 :(得分:0)
根据Release notes of git/2.14.0,现在可以支持在克隆存储库时排除标记。
"git clone" learned the "--no-tags" option not to fetch all tags initially, and also set up the tagopt not to follow any tags in subsequent fetches.
将来使用以下命令: -
git clone <repositoryUrl> --no-tags