-1

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?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Wilbert
  • 7,251
  • 6
  • 51
  • 91

1 Answers1

1

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

jacob aloysious
  • 2,547
  • 15
  • 16
  • 2
    @jacobaloysious: In order to retrieve the latest commit of a branch, the easiest way is `var commit = repo.Branches[branch_name].Tip;` ;-) – nulltoken Apr 30 '13 at 13:05