Nodegit 将提交重新绑定到其父项上

问题描述

我正在做一些非常愚蠢和具体的事情,但我需要一些帮助。

所以,我有命令

git rebase commitID --onto commitID^

我基本上是用它来从 git 历史记录中删除提交。这在终端中效果很好,但我需要找到一种方法来使用 NodeGit(LibGit 的包装器)以编程方式执行此操作。

在 repo RebaseTest 我有这样的历史

MASTER BRANCH a -> b -> c -> d -> e (HEAD)

如果我想删除b,我可以做

git rebase b --onto b^

所以我有

a -> c -> d -> e

我正在尝试使用此示例测试代码来执行此操作,但是无论我如何尝试执行 rebase,我最终都会得到一个历史记录

可以在此处找到初始化 rebase 的文档: https://www.nodegit.org/api/rebase/

const repo = await Git.Repository.open('rebaseTest');
const branch = await repo.getBranchCommit('master');
const head = await Git.AnnotatedCommit.lookup(repo,branch.id());
const commit = await Git.AnnotatedCommit.lookup(repo,'b');
const parent = await Git.AnnotatedCommit.lookup(repo,await (await commit.parent(0)).sha());
// THESE COMBINATIONS DO NOT WORK (N is null) hct ccp cpp hpc cNp cpN pcN pNc
const rebase = await Git.Rebase.init(repo,head,commit,parent);

使用不同的参数组合运行这段代码给了我一个看起来像这样的历史,

a -> b -> c (head)

完全删除所有其余的提交。也许 RebaSEOptions 会很有用,但我不确定如何。

我该如何在这函数中使用那个命令?如果不可能,我想我可以通过使用 exec 来只运行 bash 命令来做到这一点,但如果我可以避免它,我真的宁愿不这样做。是的,我理解这个古怪问题的荒谬和琐碎。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)