Is there a function equivalent to git diff FILE in libgit2? In other words, how to efficiently retrieve the diff of a single file without having libgit2 to look at other files in the working directory?
git diff FILE will display the changes you've made relative to the index.
This can be achieved through the use of the libgit2 git_diff_index_to_workdir() function.
This function accepts a git_diff_options structure as a parameter into which you can provide a pathspec, or a list of pathspecs, you're specifically interested in.
More information about this:
- Documentation of this function.
- Unit test leveraging this use case.
来源:https://stackoverflow.com/questions/16563021/how-to-get-the-diff-of-a-single-file-with-libgit2