【问题标题】:Libgit2sharp, Pushing a specific branch to new remoteLibgit2sharp,将特定分支推送到新远程
【发布时间】:2020-03-28 00:33:03
【问题描述】:

我正在编写一个 dotnet api 从 github 克隆,然后使用 Libgit2sharp 库将特定分支推送到 AWS codecommit。

  • 我在 gitHubRepo 中有两个分支,origin/release 和 origin/refactor。
  • origin/release 是默认的 git 分支
  • 我想克隆 gitHubRepo,并将 origin/refactor 分支推送到 codecommit

问题: 我似乎无法让它将我指定的分支推送到代码提交,它似乎总是推送设置为 HEAD 的内容。我不知道如何更改 HEAD,甚至不知道这是否是问题。

代码片段:

var baseRefBranch = gitHubRepo.Branches[$"origin/refactor"];
if (baseRefBranch == null) throw new Exception("refactor branch was null...");

logger.LogInformation($"Checking out branch: {baseRefBranch.CanonicalName}");
Commands.Checkout(gitHubRepo, baseRefBranch);

logger.LogInformation($"Update branch {baseRefBranch.CanonicalName}, set remote name {codeCommitRemote.Name}, set upstreamBranch to {baseRefBranch.CanonicalName}");
        gitHubRepo.Branches.Update(baseRefBranch,
            b => b.Remote = codeCommitRemote.Name,
            b => b.UpstreamBranch = baseRefBranch.CanonicalName);

var refSpec = $"+{baseRefBranch.CanonicalName}";
logger.LogInformation($"Trying to push to remote: {codeCommitRemote.Name}, refSpec: {refSpec}");
gitHubRepo.Network.Push(codeCommitRemote, refSpec, pushOptions);

任何帮助表示赞赏...干杯

【问题讨论】:

    标签: git .net-core libgit2sharp aws-codecommit


    【解决方案1】:

    尝试使用complete refsepc when pushing

    <refspec> 参数的格式是可选的加上+,后跟源对象<src>,后跟冒号:,后跟目标引用<dst>

    在你的情况下:

    +refs/heads/refactor:refs/heads/refactor
    

    【讨论】:

    • 非常感谢,在我的情况下,因为重构分支不是 HEAD,我必须这样做 +refs/remotes/origin/refactor:refs/heads/refactor 这很有效,非常感谢您为我指明了正确的方向!
    猜你喜欢
    • 2013-05-03
    • 2022-01-15
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 2014-06-13
    • 2011-09-10
    • 2016-07-08
    相关资源
    最近更新 更多