如何获得与libgit2单个文件的差异? [英] How to get the diff of a single file with libgit2?

查看:212
本文介绍了如何获得与libgit2单个文件的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有相当于 git的差异文件 libgit2 函数?换句话说,如何有效地检索文件的差异,而无需 libgit2 来看看其他的文件在工作目录?

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的差异文件将显示你对指数做出相对的变化。

git diff FILE will display the changes you've made relative to the index.

这可以通过使用libgit2来实现 git_diff_index_to_workdir()功能。

This can be achieved through the use of the libgit2 git_diff_index_to_workdir() function.

该函数接受 git_diff_options 结构作为一个参数,可以在其中提供pathspec,或pathspecs的列表,你在特别感兴趣。

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.

关于这方面更多的信息:


  • <一个href=\"https://github.com/libgit2/libgit2/blob/bc2020d64869aa19a88b71aee33a24b54c178dab/include/git2/diff.h#L543-L563\"相对=nofollow>这个函数的文档

  • <一个href=\"https://github.com/libgit2/libgit2/blob/bc2020d64869aa19a88b71aee33a24b54c178dab/tests-clar/diff/workdir.c#L203-L308\"相对=nofollow>单元测试 利用这种使用情况。

这篇关于如何获得与libgit2单个文件的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆