简体   繁体   中英

How to get all changes to a file in Git, with Lib2GitSharp

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?

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM