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.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Robert N edited this page Oct 25, 2015
·
1 revision
Git
$git cat-file {sha}:{filename}
LibGit2Sharp
repo.Head.Tip[{FilePathToContentFrom}].Target as Blob;
using (var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8))
{
commitContent = content.ReadToEnd();
}
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using LibGit2Sharp;
namespace libgitblob
{
class MainClass
{
public static void Main (string[] args)
{
var repo = new Repository ("/your/repo/path");
foreach (var item in repo.RetrieveStatus()) {
if (item.State == FileStatus.Modified) {
var blob = repo.Head.Tip[item.FilePath].Target as Blob;
string commitContent;
using (var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8))
{
commitContent = content.ReadToEnd();
}
string workingContent;
using (var content = new StreamReader(repo.Info.WorkingDirectory + Path.DirectorySeparatorChar + item.FilePath, Encoding.UTF8))
{
workingContent = content.ReadToEnd();
}
Console.WriteLine ("\n\n~~~~ Original file ~~~~");
Console.WriteLine(commitContent);
Console.WriteLine ("\n\n~~~~ Current file ~~~~");
Console.WriteLine(workingContent);
}
}
}
}
}