【问题标题】:how do I clone a git repository using node.js specific commands如何使用 node.js 特定命令克隆 git 存储库
【发布时间】:2020-12-04 19:07:39
【问题描述】:

我想使用 node.js 命令提示符克隆一个 git 存储库。我需要使用哪些命令来创建项目区域,然后将 repo 克隆到其中?

【问题讨论】:

  • 这只是一个普通的命令提示符吗? git clone <repo url> 不起作用?
  • 您的意思是使用Nodejs REPL?或者你的意思是你想写一个 Nodejs script 来做到这一点?如果您说的是 REPL,为什么?
  • 这能回答你的问题吗? How to clone github repo using node.js

标签: node.js git git-clone


【解决方案1】:

好吧,您可以使用shelljsnodegit 包。 让我描述一种使用shelljs的方法。

const shell = require('shelljs')
const path = process.cwd
shell.cd(path)
shell.exec('git clone https://github.com/<github-name>/<git-repos>')

那是一种使用nodegit的方式。

const clone = require("nodegit").Clone.clone

const path = process.cwd

clone("https://github.com/<github-name>/<git-repos>", path)
  .then(function () {
    // Repo is available in `path`
  })

【讨论】:

    【解决方案2】:

    添加到@Venus713 的解决方案,您可以使用node-cmd 克隆存储库。

    const cmd = require('node-cmd');
    const clone = cmd.runSync('git clone https://github.com/<username>/<repo>');
    
    // runSync returns the output of the command, which is console logged below.
    
    console.log(clone);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-31
      • 2017-03-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2017-08-07
      • 1970-01-01
      • 2011-05-18
      相关资源
      最近更新 更多