Pregunta

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?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top