问题描述
我有一个git repo我想做一个浅拷贝,并且只拉一个分支。
说git clone默认会拉动所有远程分支。我想只做一个分支的浅表副本。
我正在执行此操作以部署到生产环境中。全额结账超过400MB,但是头部的git存档只有16MB。看起来克隆的拉下所有分支的行为导致我的下载比必要的大得多。
,但相当复杂做$。
然后他补充说:
我会补充说,你不应该有任何VCS工具一个生产平台(您只安装/监控生产所需的 run )。
So (Ralf Thielow,Git 1.7.12.3,Oct. 2012)
clone --single :将fetch refspec限制为获取分支
- ,Git 2.0.2,2014年7月)
builtin / clone.c:检测从标签开始的克隆正确
2016年9月更新: 2.11+(2016年第四季度)。
I have a git repo I'd like to do a shallow copy on, and only pull a single branch.
This SO question says that git clone by default pulls all remote branches. I'd like to do a shallow copy of only a single branch.
I'm doing this to deploy into production. A full checkout is over 400MB, but a git archive of head is only 16MB. It appears that clone's behavior of pulling down all the branches causes my download to be much larger than necessary.
Jakub already mentioned a shallow clone of selected branches is possible, but quite complex to do.
And he added:
I would add that you shouldn't have any VCS tool in a production plateform (you only install/monitor what is necessary for the production to run).
So git archive remains the best way to extract just what you need, as an archive (zip or tar, format that you can then uses without Git, once transferred on the production side)
Update March 2012:
the upcoming git1.7.10 (April 2012) will actually allow you to clone only one branch:
git clone --single-branch
You can see it in t5500-fetch-pack.sh:
test_expect_success 'single branch clone' ' git clone --single-branch "file://$(pwd)/." singlebranch '
That feature was then fixes with:
- commit 31b808a03290a4f87c571cc1c61f26d8a03c7025 (Ralf Thielow, Git 1.7.12.3, Oct. 2012)
clone --single: limit the fetch refspec to fetched branch
- commit 60a5f5f (Junio C Hamano (gitster), Git 2.0.2, July 2014)
builtin/clone.c: detect a clone starting at a tag correctly
Update Sept 2016: git clone --single-branch --branch tag will work for chained tags in Git 2.11+ (Q4 2016).
这篇关于如何在git中克隆单个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!