简体   繁体   English

是否可以使用 Libgit2sharp 从特定标签克隆?

[英]Is it possible to clone from a specific tag using Libgit2sharp?

Using LibGit2Sharp, I can do a clone from a specific remote branch :).使用 LibGit2Sharp,我可以从特定的远程分支进行克隆 :)。 Now, I want to clone a repo from a specif tag, say "v1".现在,我想从特定标签中克隆一个 repo,比如“v1”。 I found this link but it does not help me.我找到了这个链接,但它对我没有帮助。 how to clone specific tag using git_clone() in libgit2 如何在 libgit2 中使用 git_clone() 克隆特定标签

I thought I might be able to specifiy the tag with CloneOptions.BranchName (I know this is for a branch but I thought I should try anyway before posting my question) but it did not succeed.我想我可以用 CloneOptions.BranchName 指定标签(我知道这是一个分支,但我认为在发布我的问题之前我应该​​尝试一下)但它没有成功。 Here's the C# code I have.这是我拥有的 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);

Is it possible to clone from a specific tag?是否可以从特定标签克隆?

From what I found you cant directly Clone repo based on tag.从我发现你不能直接基于标签克隆回购。 But you can make a clone of the branch and then checkout to the tag specified.但是您可以克隆分支,然后签出到指定的标签。 Something like:就像是:

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);
}

where commitSpecifier is the tag name and projectRepositoryPath is the path to your local repository directory其中commitSpecifier是标签名称, projectRepositoryPath是本地存储库目录的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM