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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.