Javascript NodeGit:在不签出的情况下将分支指针移动到不同的提交
在git中,我们可以使用以下命令来实现它:Javascript NodeGit:在不签出的情况下将分支指针移动到不同的提交,javascript,node.js,git,Javascript,Node.js,Git,在git中,我们可以使用以下命令来实现它: git branch -f branch-name new-tip-commit 我们如何在nodegit中实现同样的目标 您可以尝试重新创建分支,即使分支已经存在,也可以强制创建 见,其中包括: @param {bool} force Overwrite branch if it exists 您可以在中看到一个示例: 在该示例中,如果将0替换为1,则即使分支已经存在,也会强制创建该分支,从而有效地将其头部重置为新提交。谢谢,它工作正常,但如果
git branch -f branch-name new-tip-commit
我们如何在nodegit中实现同样的目标
您可以尝试重新创建分支,即使分支已经存在,也可以强制创建 见,其中包括:
@param {bool} force Overwrite branch if it exists
您可以在中看到一个示例:
在该示例中,如果将
0
替换为1
,则即使分支已经存在,也会强制创建该分支,从而有效地将其头部重置为新提交。谢谢,它工作正常,但如果分支当前已签出,则会失败。git重置呢——硬@adnankamili
var nodegit = require("../");
var path = require("path");
nodegit.Repository.open(path.resolve(__dirname, "../.git"))
.then(function(repo) {
// Create a new branch on head
return repo.getHeadCommit()
.then(function(commit) {
return repo.createBranch(
"new-branch",
commit,
0,
repo.defaultSignature(),
"Created new-branch on HEAD");
});
}).done(function() {
console.log("All done!");
});