Skip to content
KindDragon edited this page Apr 19, 2013 · 6 revisions

git-diff

Compare with index or with working directory

Return changes in working directory

Git

$ git diff

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    foreach (TreeEntryChanges c in repo.Diff.Compare(repo.Head.Tip.Tree,
                                                  DiffTargets.WorkingDirectory);)
    {
        Console.WriteLine(c));
    }
}

Return changes in index

Git

$ git diff --cached

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    foreach (TreeEntryChanges c in repo.Diff.Compare(repo.Head.Tip.Tree,
                                                  DiffTargets.Index);)
    {
        Console.WriteLine(c));
    }
}

Return changes in index and working directory

Git

$ git diff HEAD

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    foreach (TreeEntryChanges c in repo.Diff.Compare(repo.Head.Tip.Tree,
                                                  DiffTargets.WorkingDirectory);)
    {
        Console.WriteLine(c));
    }
}

Clone this wiki locally