【问题标题】:How to create a new tag in a local repo using LibGit2Sharp?如何使用 LibGit2Sharp 在本地仓库中创建新标签?
【发布时间】:2021-08-05 17:54:13
【问题描述】:

我想使用 LibGit2Sharp 在我的本地仓库中创建一个新的轻量级标签。我无意将其推送到遥控器(我使用标签作为短期书签);知道如何推送到远程会很方便,但我最感兴趣的只是在本地仓库中创建一个标签而不推送到远程。

【问题讨论】:

    标签: c# libgit2sharp


    【解决方案1】:

    如下:

    using LibGit2Sharp;
    
        /// <summary>
        /// Create a lightweight tag in the specified local repo:
        /// </summary>
        /// <param name="tagName">Name to be given to the tag</param>
        /// <param name="repoFolder">Repo folder location (path)</param>
        /// <param name="commitSha">Hash identifying the commit to receive the tag</param>
        public static void CreateTag(string tagName, string repoFolder, string commitSha)
        {
            using (var repo = new Repository(repoFolder))
            {
                var commit = repo.Lookup<Commit>(commitSha);
                if (commit != null)
                {
                    repo.ApplyTag(tagName, commitSha);
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-07
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 2022-06-24
      • 2012-01-17
      相关资源
      最近更新 更多