如何使用libgit2创建一个空的提交? [英] How can I create an empty commit using libgit2?

查看:130
本文介绍了如何使用libgit2创建一个空的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看 libgit2 C API参考,但是我看不到如何可以模拟git commit --allow-empty的行为. libgit2是否具有创建空提交的内置方法?如果没有,git如何在后台创建一个空的提交,我该如何使用libgit2实现相同的行为?

I've been looking over the libgit2 C API reference, but I don't see how I could emulate the behaviour of git commit --allow-empty. Does libgit2 have a built-in way to create empty commits? If not, how does git create an empty commit under-the-hood, and how should I go about achieving the same behaviour using libgit2?

推荐答案

使用与父提交相同的树来调用git_commit_create.那就是:

Call git_commit_create with the same tree as the parent commit. That is:

// Get parent somehow.
git_commit *parent = ...;

// Use the same tree as the parent.
git_tree *tree;
git_commit_tree(&tree, parent);

// Create the commit.
git_commit_create(..., tree, 1, parent);

这篇关于如何使用libgit2创建一个空的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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