How to ignore the merge using libgit2sharp?

I need to get a list of commits without the automatic merges done by Git. How can this be done using the libgit2sharp package?

+3


source to share


1 answer


Merge reconciliation is a multi-parent commit.

To do this with Git, one could specify, for example, the following command, which would list all commits reachable by HEAD that are not commits.

git log --no-merges HEAD

      

Where is documented as "Do not print commits with multiple parents. Same as --max-parents = 1.".--no-merges




You can do the same with LibGit2Sharp with the following piece of code:

using (var repo = new Repository(path))
{
    var allCommitsReachableByHead = repo.Commits;

    const string RFC2822Format = "ddd dd MMM HH:mm:ss yyyy K";

    foreach (var c in allCommitsReachableByHead)
    {
        if (c.Parents.Count() > 1)
        {
            continue;
        }

        Console.WriteLine("Author: {0} <{1}>", c.Author.Name, c.Author.Email);
        Console.WriteLine("Date:   {0}", c.Author.When.ToString(RFC2822Format, CultureInfo.InvariantCulture));
        Console.WriteLine();
        Console.WriteLine(c.Message);
        Console.WriteLine();
    }
}

      

+5


source







All Articles