在 LibGit2Sharp 中查找合并的祖先路径

Finding Ancestry Path of a merge in LibGit2Sharp

在 Git 中,我可以使用以下命令获取与合并相关的所有提交:

bases=$(git merge-base --all --octopus A B C)

git log --pretty=%H --ancestry-path A B C --not $bases
echo $bases

LibGit2Sharp 中是否有与此等效的内容?

repo.ObjectDatabase.FindMergeBase() 应该有助于解决第一步

/// <summary>
/// Find the best possible merge base given two or more <see cref="Commit"/> according
/// to the <see cref="MergeBaseFindingStrategy"/>.
/// </summary>
/// <param name="commits">
/// The <see cref="Commit"/>s for which to find the merge base.
/// </param>
/// <param name="strategy">
/// The strategy to leverage in order to find the merge base.
/// </param>
/// <returns>The merge base or null if none found.</returns>
public virtual Commit FindMergeBase(IEnumerable<Commit> commits,
     MergeBaseFindingStrategy strategy)

repo.Commits.QueryBy(new CommitFilter { Since = commits, Until = bestMergeBase }); 将是枚举相关提交的方式。

根据您的评论更新

Does that replicate the --all flag of git merge-base?

没有。此方法将仅返回 "best" 计算的合并基础。

一个git_merbe_bases_many() function exists in libgit2 that would allow to replicate --all. However, it's not been bound to libGit2Sharp yet. Would you be interested in it, please log a feature request in the issue tracker