Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeGit:在不签出的情况下将分支指针移动到不同的提交_Javascript_Node.js_Git - Fatal编程技术网

Javascript NodeGit:在不签出的情况下将分支指针移动到不同的提交

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中,我们可以使用以下命令来实现它:

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!");
  });