Return patch changes in a specific file between commits in a repository
Git
$ git diff
LibGit2Sharp
stringresult;
using (varrepo=newRepository("path/to/your/repo"))
{
List<Commit> CommitList=newList<Commit>();
foreach (LogEntryentryinrepo.Commits.QueryBy("relative/path/to/your/file").ToList())
CommitList.Add(entry.Commit);
CommitList.Add(null); // Added to show correct initial addintChangeDesired=0; // Change difference desiredvarrepoDifferences=repo.Diff.Compare<Patch>((Equals(CommitList[ChangeDesired+1], null)) ?null:CommitList[ChangeDesired+1].Tree, (Equals(CommitList[ChangeDesired], null)) ?null:CommitList[ChangeDesired].Tree);
PatchEntryChangesfile=null;
try { file=repoDifferences.First(e=>e.Path=="relative/path/to/your/file");}
catch {} // If the file has been renamed in the past- this search will failif (!Equals(file, null))
{
result=file.Patch;
}
}
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
Learn more.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
You can always update your selection by clicking Cookie Preferences at the bottom of the page.
For more information, see our Privacy Statement.
Essential cookies
We use essential cookies to perform essential website functions, e.g. they're used to log you in.
Learn more
Always active
Analytics cookies
We use analytics cookies to understand how you use our websites so we can make them better, e.g. they're used to gather information about the pages you visit and how many clicks you need to accomplish a task.
Learn more