2017-02-10 68 views

回答

2

libgit2wiki文件後,可以修改他們的示例代碼看起來像這樣:

using (var repo = new Repository("path/to/your/repo")) 
{ 
    const string commitSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644"; 
    foreach(Branch b in ListBranchesContainingCommit(repo, commitSha)) 
    { 
     Console.WriteLine(b.Name); 
    } 
} 

private IEnumerable<Branch> ListBranchesContainingCommit(Repository repo, string commitSha) 
{ 
    var commit = repo.Lookup<Commit>(commitSha);var commit = repo.Lookup<Commit>(commitSha); 

    IEnumerable<Reference> headsContainingTheCommit = repo.Refs.ReachableFrom(repo.Refs, new[] {commit}); 
    return headsContainingTheCommit.Select(branchRef => repo.Branches[branchRef.CanonicalName]).ToList(); 
} 
+0

太好了!這工作 - 感謝代碼 –

+0

不客氣:-) – Slartibartfast