문제

I am using LibGit2Sharp and would like to get the latest commit of a specific branch, but, due to lacking documentation or my own fault I cannot find out how to achieve this.

Therefore, what's the easiest way to get the current commit of a specific branch?

도움이 되었습니까?

해결책

Here is a sample to get the latest commit in a branch.

        IRepository repository = new Repository(@"D:\Code\MYRepoLocation\.git");

        foreach (var branch  in repository.Branches)
        {
            var listOfCommits = branch.Commits;
            var latestCommit = listOfCommits.First();
        }

You could also pick a specific branch by giving its name

var myBranch2Dot0 = repository.Branches["bug2.0"];

Note: These are the branches available locally, and not the one in Remote

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top