相当于git merge origin/master in libgit2

Equivalent to git merge origin/master in libgit2

我正在使用 libgit2 C 版本 0.20.0 库。我已经成功地实现了更新 oid 的 git_remote_fetch() 但之后我无法正确调用合并方法。

试图调用 int git_merge(git_repository *repo, const git_annotated_commit **their_heads, size_t their_heads_len, const git_merge_options *merge_opts, const git_checkout_options *checkout_opts);但是第二个参数 git_annotated_commit 应该是常量。我从方法 git_annotated_commit_lookup() 方法中得到 git_annotated_commit **out。 body 可以告诉我如何将 git_annotated_commit **out 转换为 const 吗?有没有其他方法可以将 git_annotated_commit **out 作为常量?

使用 Git bash 控制台我执行命令 git merge origin/master 成功更新存储库的内容,是否可以body 告诉我我需要在 libgit2 中使用哪个命令来做同样的事情?

为了将 git_annotated_commit **out 转换为 const git_annotated_commit **their_heads,您应该使用:const_cast,例如:

const git_annotated_commit **their_heads = const_cast<const git_annotated_commit**>(out);