如何将 Git 浅克隆转换为完整克隆?

发布于 2024-11-26 12:26:40 字数 147 浏览 2 评论 0原文

这个这样的问题的后续:如果我有浅克隆,如何获取所有较旧的提交以使其成为完整克隆?

Follow-up of this so-question: if I have a shallow clone, how to fetch all older commits to make it a full clone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

若能看破又如何 2024-12-03 12:26:40

下面的命令(git版本1.8.3)会将浅克隆转换为常规克隆

git fetch --unshallow

然后,访问origin上的所有分支(感谢评论中的@Peter)

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

The below command (git version 1.8.3) will convert the shallow clone to regular one

git fetch --unshallow

Then, to get access to all the branches on origin (thanks @Peter in the comments)

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
总以为 2024-12-03 12:26:40

编辑: git fetch --unshallow 现在是一个选项(感谢 Jack O'Connor)。

您可以

从浅层上的文档git fetch --depth=2147483647 >:

特殊深度 2147483647(或 0x7fffffff,有符号 32 位整数可以包含的最大正数)意味着无限深度。

EDIT: git fetch --unshallow now is an option (thanks Jack O'Connor).

You can run git fetch --depth=2147483647

From the docs on shallow:

The special depth 2147483647 (or 0x7fffffff, the largest positive number a signed 32-bit integer can contain) means infinite depth.

梦忆晨望 2024-12-03 12:26:40

我需要将存储库深化到特定的提交。

读完 man git-fetch 后,我发现不能指定提交,但可以指定日期:

git fetch --shallow-since=15/11/2012

对于需要增量深化的人,再引述一下 man

--deepen=<深度>

与--depth类似,不同之处在于它指定了深度的数量
从当前浅边界而不是从尖端提交
每个远程分支历史记录。

I needed to deepen a repo only down to a particular commit.

After reading man git-fetch, I found out that one cannot specify a commit, but can specify a date:

git fetch --shallow-since=15/11/2012

For those who need incremental deepening, another man quote:

--deepen=<depth>

Similar to --depth, except it specifies the number of
commits from the current shallow boundary instead of from the tip
of each remote branch history.

千鲤 2024-12-03 12:26:40

实现浅克隆到深克隆的两种方法。 :

  1. 使用以下步骤下载分支:(这将下载分支的浅表副本,然后将其转换为完整克隆,即带来完整的分支及其历史记录)。

    a. git clone -b 分支 http://git.repository/customSP01.git --深度 1

这会执行浅克隆(带有深度选项)仅获取一个分支(在您请求的深度)。

b. cd customSP01
c. git fetch --depth=100
d. get fetch --depth=500
....
e. git fetch --unshallow    

//上述命令会将浅克隆转换为常规克隆。
然而,这并没有带来所有分支:

然后,访问所有分支。

f. git remote set-branches origin '*'

[此步骤也可以通过编辑 .git/config 中的以下行来手动完成。

fetch = +refs/heads/master:refs/remotes/origin/master

到(用 * 替换 master):

fetch = +refs/heads/*:refs/remotes/origin/*
]

g. git fetch -v

这会将浅克隆转换为具有所有历史和分支详细信息的深克隆。


  1. 如果您使用以下命令而不是步骤 a 中的命令,则可以避免步骤 f 和 g。进行浅克隆:

    git 克隆 -b 分支 --no-single-branch http://git.repository/customSP01.git< /a> --深度1


Two ways to achieve Shallow Clone to Deep Clone. :

  1. Used the following steps to download the branch: (This downloads the shallow copy of the branch and then converts it into a Full Clone i.e bring complete branch and its history).

    a. git clone -b branch http://git.repository/customSP01.git --depth 1

This does a shallow clone (with the depth-option) only fetches only one single branch (at your requested depth).

b. cd customSP01
c. git fetch --depth=100
d. get fetch --depth=500
....
e. git fetch --unshallow    

//The above command will convert the shallow clone to regular one.
However, this doesn’t bring all the branches:

Then, to get access to all the branches.

f. git remote set-branches origin '*'

[This Step can also be done manually by editing following line in .git/config.

fetch = +refs/heads/master:refs/remotes/origin/master

to (replace master with *):

fetch = +refs/heads/*:refs/remotes/origin/*
]

g. git fetch -v

This converts the Shallow Clone into Deep Clone with all the History and Branch details.


  1. You can avoid steps f and g, if you use the below instead of command present in step a. to do the shallow clone:

    git clone -b branch --no-single-branch http://git.repository/customSP01.git --depth 1

伴我心暖 2024-12-03 12:26:40

你可以试试这个:

git fetch --update-shallow

You can try this:

git fetch --update-shallow
不气馁 2024-12-03 12:26:40

上述消息都没有起到作用。我正在尝试从浅克隆开始使用 git 标签。

首先我尝试了

git fetch --update-shallow

中途哪种方法有效。
然而,没有可用的标签!

git fetch --depth=1000000

最后一个命令确实获取了标签,我终于可以执行

git checkout -b master-v1.1.0 tags/v1.1.0

并完成它了。

华泰

None of the above messages did the trick. I'm trying to work with git tags starting from a shallow clone.

First I tried

git fetch --update-shallow

which kind of worked half-way through.
Yet, no tags available!

git fetch --depth=1000000

This last command really fetched the tags and I could finally execute

git checkout -b master-v1.1.0 tags/v1.1.0

and be done with it.

HTH

岁月蹉跎了容颜 2024-12-03 12:26:40

有助于解决该错误的配置是
(在亚搏体育app实验室)
对于每个项目:

  1. 在顶部栏上,选择“主菜单”>“项目并找到您的项目。
  2. 在左侧边栏上,选择“设置”>“持续集成/持续交付。展开一般
    管道。
  3. 在Git策略下选择git fetch,在Gitshallow下选择
    克隆,输入一个值,1000,GIT_DEPTH 的最大值阅读更多 - https://gitlab.yourcompany.com/help/ci/pipelines/settings#limit-the-number-of-changes-fetched-during-clone{}

在 .gitlab-ci-yml 中(这应该在调用 GitVersion.exe 的任何命令之前完成)

  before_script:
    - git fetch --prune --tags --unshallow  

Configurations that helped with the error is
(In GitLab)
For each project :

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD. Expand General
    pipelines.
  3. Under Git strategy, choose git fetch, under Git shallow
    clone, enter a value, 1000, the maximum value for GIT_DEPTH Read More - https://gitlab.yourcompany.com/help/ci/pipelines/settings#limit-the-number-of-changes-fetched-during-clone{}

In the .gitlab-ci-yml (this should be done before any command that calls GitVersion.exe)

  before_script:
    - git fetch --prune --tags --unshallow  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文