代码之家  ›  专栏  ›  技术社区  ›  Will Da Silva Alex Martelli

如何使用libgit2创建空提交?

  •  4
  • Will Da Silva Alex Martelli  · 技术社区  · 6 年前

    我一直在看报纸 libgit2 C API reference ,但我不明白我怎么能模仿 git commit --allow-empty . libgit2是否有创建空提交的内置方法?如果不是,git如何在引擎盖下创建空提交,我应该如何使用libgit2实现相同的行为?

    1 回复  |  直到 6 年前
        1
  •  7
  •   Jason Haslam    6 年前

    git_commit_create 与父提交具有相同的树。即:

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