问题描述
我只想将我的本地存储库与我的遥控器的子目录进行比较。虽然是本机 git 命令,但我可以通过以下方式实现:
git diff master <a remote commit>:>directory>
如何通过 Rust git2 crate 实现这一点?
解决方法
正如@o11c 所提到的,这是通过 git_diff_tree_to_tree
函数在 C 库中公开的,它对应于 Rust 中的 Repository::diff_tree_to_tree
。
master
将在 old_tree
参数中传递,<a remote commit>
在 new_tree
中传递,而 <directory>
可以与 opts
参数一起指定,使用 DiffOptions::pathspec
构造。