【发布时间】: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