Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Git diff

KindDragon edited this page Apr 19, 2013 · 6 revisions

git-diff

Compare with working directory or index

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