Skip to content
nulltoken edited this page May 26, 2011 · 14 revisions

git-log

Show HEAD commit logs

Limiting the number of commits to show

Git

$ git log -15

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    foreach (Commit c in repo.Commits.Take(15))
    {
        Console.WriteLine(c.Id);   // Of course the output can be prettified ;-)
    }
}

Changing the order of the commits

Git

$ git log --topo-order --reverse

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    var filter = new Filter { SortBy = GitSortOptions.Topological | GitSortOptions.Reverse };

    foreach (Commit c in repo.Commits.QueryBy(filter))
    {
        Console.WriteLine(c.Id);   // Of course the output can be prettified ;-)
    }
}

Show only commits between two named commits

Git

$ git log master..development

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    var filter = new Filter { Since = repo.Branches["master"], Until = repo.Branches["development"] };

    foreach (Commit c in repo.Commits.QueryBy(filter))
    {
        Console.WriteLine(c.Id);   // Of course the output can be prettified ;-)
    }
}
Clone this wiki locally