-
Notifications
You must be signed in to change notification settings - Fork 889
git cat file
Piyush Rungta edited this page Jun 23, 2024
·
2 revisions
$git cat-file {sha}:{filename}
repo.Head.Tip[{FilePathToContentFrom}].Target as Blob;
using (var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8))
{
commitContent = content.ReadToEnd();
}
From StackOverFlow
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);
}
}
}
}
}