0

I want to be able to Get a list of all changes done to a file. I've seen this post How to get file's contents on Git using LibGit2Sharp?, but this requires to start off with a commit. I want to start digging with the filename.

Also is this possible without getting the whole repo locally?

Community
  • 1
  • 1
schultz
  • 316
  • 2
  • 14

2 Answers2

1

After a bit of research I think I found an answer.

            /*Small test*/
            using (Repository repo = new Repository(strLocalDeliveryPath))
            {
                var fileHistory = repo.Commits.QueryBy(@"Path/To/file.ini").ToList();

                int i = fileHistory.Count();
            }

This is in order newest to oldest, and that suits me fine. I would normally only need the latest version of the file content, but nor i have the option of digging through the history of the file.

schultz
  • 316
  • 2
  • 14
1

You can see this answer for a bit more info, but yes, the functionality was added in libgit2sharp 0.22.0. Here's an example:

var fileHistory = repository.Commits.QueryBy(filePathRelativeToRepository);
foreach (var version in fileHistory)
{
    // Get further details by inspecting version.Commit
}
Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118