如何使用 JGit/EGit 恢复合并提交

How to revert a merge commit using JGit/EGit

我了解到 JGit 不支持 git revert -m 1 <SHA> 命令。有没有其他使用 JGit 的方法可以帮助我恢复合并?

JGit 目前无法恢复合并提交(或者更一般地说,与多个父级的提交)。如果任何 includeed 提交是合并提交,它将抛出 MultipleParentsNotAllowedException

除了调整和修改 ResetCommand 源代码或(甚至更好)对 JGit 做出更改外,我不知道有什么解决方法。

如果您在 RevertCommand 源代码中搜索 MultipleParentsNotAllowedException,您就接近需要进行更改的地方了。下面几行,源父级是这样确定的:

RevCommit srcParent = srcCommit.getParent(0);

需要更改为:

RevCommit srcParent = srcCommit.getParent(mainlineIndex);

当然还有 getter 和 setter 用于 mainlineIndex