How can I create an empty commit using libgit2?

核能气质少年 提交于 2019-12-10 15:19:57

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/52188664/how-can-i-create-an-empty-commit-using-libgit2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!