使用 libgit2 将所有提交合并到单个提交中的方法

way to combine all commits into a single commit using libgit2

本文关键字:提交 单个 方法 合并 使用 libgit2      更新时间:2023-10-16

我想将所有提交合并为一个以删除历史记录。我知道在 Git 命令行中这是可能的,但我还没有在 libgit2 中找到方法。

我在

最新版本中使用libgit2,由我在C++年编译。

你有什么建议?

有几种方法可以考虑这个问题。在命令行上,您可以执行以下操作:

git reset --soft <some-ancestor-commit-ish>
git commit -m "This commit combines some history."

软重置将当前分支移动到指向某个祖先提交,而不更改工作目录和索引。因此,现在您已经暂存了这些提交引入的所有更改,并且可以将它们作为新的组合提交提交。这两个步骤可以直接转换为 libgit2

,如下所示:
git_reset(repo, ancestor_commit, GIT_RESET_SOFT, NULL);
git_commit_create(...);