【问题标题】:How to push a directory from NodeJs to Git (GitHub)如何将目录从 NodeJs 推送到 Git (GitHub)
【发布时间】:2021-10-24 04:39:24
【问题描述】:

我有一个 NodeJs 服务器会生成一些文件,我需要将这些文件自动推送到 git 存储库(具体为 GitHub)。

The same question has been asked here 但它很旧,并没有真正的答案或一些基本示例。

到目前为止我搜索并发现的内容:

  • 很多在线博客都建议使用 Git Bash,但没有一个显示任何示例,而且我是 NodeJS 新手,从未在 NodeJs 服务器中使用过它。
  • 有类似 NodeGit [Website] [GitHub] 之类的东西,对我来说,它似乎主要专注于从 git 中提取数据,并且从 NodeJs 目录中推送特定目录的示例是对我来说相当模糊或有点难以理解。 Link to the NodeGit #Push Documentation
  • 还有 git-js [GitHub],我也缺乏了解如何推送特定目录或文件夹。文档中的一些示例:.push(remote, branch[, options])

【问题讨论】:

  • 这些文件的用途是什么?通常,您不应将生成的文件签入存储库。
  • @bk2204 将一些 JSON 文件推送到 GitHub,然后推送到 Netlify,它会根据 JSON 文件的内容生成一个带有站点生成器的 JamStack / 静态站点。

标签: javascript node.js git github push


【解决方案1】:

我会做类似的事情:

require('child_process').execFile('git', ['commit', '-am', 'xxx']);

require('child_process').execFile('git', ['push']);

require('child_process').execFile('sh', ['-c', 'git commit -am xxx && git push']);

无依赖,失败概率低:)

在这里查看更多: https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

【讨论】:

    猜你喜欢
    • 2016-05-21
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 2013-05-30
    相关资源
    最近更新 更多