Search code examples
c#gitvisual-studiolibgit2sharp

Whats the simplest way to return all commits on git to master branch that have not been merged already?


I'm using LigGit2Sharp. I've tried using

foreach (Commit commit in repo.Commits)
{
    foreach (var parent in commit.Parents)
    {
        //Console.WriteLine("{0} | {1}", commit.Sha, commit.MessageShort);
    }
}

However this shows all of the commits history...


Solution

  • What you want to do is create a filtered list (ICommitLog) between two commit-ish (commits, trees, tags, ...).

    This is a example of getting all the commits between the tip of two branches; a "master" branch and a bug fix branch that has had changes made to it but not merged yet to "master":

    public ICommitLog CommitList {
        get {
            var filter = new CommitFilter { 
                SortBy = CommitSortStrategies.Reverse | CommitSortStrategies.Time,
                Since = repo.Branches.Single (branch => branch.FriendlyName == "bugfix1234");
                Until = repo.Branches.Single (branch => branch.FriendlyName == "master");           
            };
            return repo.Commits.QueryBy (filter);
        }
    }