2017-11-29 5 views
0

로컬 드라이브에 저장소를 복제했습니다. libgit2sharp를 사용하여 브랜치를 생성 할 수있었습니다. 아래는 내가 사용한 코드입니다.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 서버에서 분기를 볼 수 있습니다.

그러나 내가 만든 분기로 파일을 커밋하려고하면 원격 자식에서 볼 수 없습니다.

다음은 코드입니다.

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()); 

참고 : 요구 사항은 마스터 지점이 파일이 없어야합니다 파일 만 지점을 지정하기 위해 최선을 다하고해야한다는 것입니다.

답변

0

첫 번째 스 니펫에서는 분기를 생성하고 푸시합니다. 두 번째 단계에서는 커밋을합니다. 일부 코드를 생략하지 않는 한, 생성 한 분기로 전환하는 것이 아닙니다.

LibGit2Sharp.Commands.Checkout(repo, branch); 

이 작업을 완료하면 커밋 한 다음 분기를 푸시 할 수 있습니다.

관련 문제