![](/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.