![](/img/trans.png)
[英]Is there a way to fetch a specific tag from a remote git repository using libgit2sharp ?
[英]Is it possible to clone from a specific tag using Libgit2sharp?
使用 LibGit2Sharp,我可以从特定的远程分支进行克隆 :)。 现在,我想从特定标签中克隆一个 repo,比如“v1”。 我找到了这个链接,但它对我没有帮助。 如何在 libgit2 中使用 git_clone() 克隆特定标签
我想我可以用 CloneOptions.BranchName 指定标签(我知道这是一个分支,但我认为在发布我的问题之前我应该尝试一下)但它没有成功。 这是我拥有的 C# 代码。
var co = new CloneOptions();
co.BranchName = "v1"; // "refs/tags/v1" does not work either
co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = "username", Password = "password" };
Repository.Clone(repoUrl, localGitPath, co);
是否可以从特定标签克隆?
从我发现你不能直接基于标签克隆回购。 但是您可以克隆分支,然后签出到指定的标签。 就像是:
var repositoryOptions = new RepositoryOptions { WorkingDirectoryPath = <projectRepositoryPath> };
var checkoutOptions = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force};
using (var repo = new Repository(<projectRepositoryPath>, repositoryOptions))
{
var result = Commands.Checkout(repo, <commitSpecifier>, checkoutOptions);
}
其中commitSpecifier
是标签名称, projectRepositoryPath
是本地存储库目录的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.