【问题标题】:libgit2sharp not able to commit files only to particular Branch. Help requiredlibgit2sharp 不能只将文件提交到特定的分支。需要帮助
【发布时间】:2018-05-12 23:08:21
【问题描述】:

我在本地驱动器中克隆了一个 repo。并且能够使用 libgit2sharp 创建分支。下面是我用过的代码。

//Clone
var WorkDir = Repository.Clone(<git-url>, <local-path>);

//Branch create 
var branch = repo.CreateBranch("<branchName>");                     

repo.Branches.Update(branch,
    b => b.Remote = repo.Network.Remotes["origin"].Name,
    b => b.UpstreamBranch = branch.CanonicalName);

repo.Network.Push(branch);

上面的代码有效,我可以看到本地 .git 文件夹和 git 服务器上的分支。

但是,当我尝试将文件提交到创建的分支时,它们在远程 git 中不可见。

下面是代码。

Commands.Stage(repo, <local-clone-path-with-file>);                    
serName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split(new string[] { "\\" }, StringSplitOptions.None)[1];

// Create the committer's signature and commit
Signature author = new Signature(userName,userName+"@atkinsglobal.com", DateTime.Now);
Signature committer = author;

string comment = timeStamp + "_" + "<BranchName>" + "_" + userName;

//// Commit to the repository
Commit commit = repo.Commit(comment+"_initial", author, committer);

Remote remote = repo.Network.Remotes["origin"];

repo.Network.Push(remote, @"refs/heads/"+<BranchName>, new PushOptions());

请注意:要求文件必须只提交到指定的分支,主分支不能有这些文件。

【问题讨论】:

    标签: git git-commit git-clone libgit2 libgit2sharp


    【解决方案1】:

    在第一个 sn-p 中,您正在创建一个分支并推送它。第二,你正在承诺。除非您省略了一些代码,否则您绝不会切换到您创建的分支。

    LibGit2Sharp.Commands.Checkout(repo, branch);
    

    完成后,您可以提交它,然后推送分支。

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      相关资源
      最近更新 更多