[英]Checkout a specific commit with NodeGit
I have a NodeGit repository object, repo
, and a string sha
code which represents a commit id, commit_id
.我有一个 NodeGit 存储库 object,
repo
和一个代表提交 ID 的字符串sha
代码commit_id
。 How can I perform a git checkout of this commit using NodeGit, which would act the same as the command git checkout $commit_id
?如何使用 NodeGit 执行此提交的 git 签出,其作用与命令
git checkout $commit_id
相同?
So far, I have tried creating a Reference
using the commit id and then using checkoutRef
to check out the reference.到目前为止,我已经尝试使用提交 ID 创建
Reference
,然后使用checkoutRef
来检查参考。 However, the repository does not change and I get the error Error: the given reference name '<my commit id>' is not valid
.但是,存储库没有更改,我收到错误
Error: the given reference name '<my commit id>' is not valid
。
NodeGit.Reference.lookup(repo, commit_id, (reference) => {
repo.checkoutRef(reference)
});
Thanks for the help.谢谢您的帮助。
The only solution I've found so far is:到目前为止,我发现的唯一解决方案是:
const commit = await repo.getCommit(commit_id);
await nodegit.Reset.reset(repo, commit, nodegit.Reset.TYPE.HARD);
But it's so slow... Especially for big repositories!但它太慢了......尤其是对于大型存储库!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.