是可能使用libgit2执行`git clone –depth=1 <repository>` 吗?

huangapple go评论57阅读模式
英文:

Is it possible to do `git clone --depth=1 <repository>` with libgit2?

问题

我想要快速克隆,而不获取所有 .git 历史记录。是否可以使用 libgit2 来实现这一点?

我找到了 这个问题,但我不确定他们提到的稀疏检出是否与运行 git clone --depth=1 https://github.com/libgit2/libgit2 相同。

英文:

I want to do a quick clone without getting all the .git history. Is this possible to do with libgit2?

I found this issue but I am not sure if this sparse checkout they reference is

same as running git clone --depth=1 https://github.com/libgit2/libgit2.

答案1

得分: 2

这是现在可以实现的!libgit2的git_clone函数以git_clone_options作为参数。该结构的一个成员是git_fetch_options,它带有一个深度参数。

请注意,要模仿git clone --depth=1 https://github.com/libgit2/libgit2,您还需要仅获取单个分支的历史记录。这可以通过通过remote_cb传递您自己的回调函数来实现。

英文:

This is now possible! The libgit2 git_clone function takes git_clone_options as an argument. One of the members of that struct is git_fetch_options which takes a depth parameter.

Note that to mimic git clone --depth=1 https://github.com/libgit2/libgit2 you will also need to fetch only the history for a single branch. This is achieved by passing your own callback via remote_cb.

huangapple
  • 本文由 发表于 2023年3月8日 17:56:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定