@figma/nodegit

中文文档
0.28.0-figma.9发布于 2025/11/21MITCommonJS近 30 天下载 3208

Node.js libgit2 同步本地绑定

中文使用文档
文档目录9 节
  1. 有问题吗? 跟我们聊聊吧!
  2. 维护者
  3. 校友维护者
  4. API文档.
  5. 开始吧.
  6. API的例子.
  7. 复制寄存器并读取文件 :
  8. 模拟 git 日志 :
  9. 单位测试.

节点吉特

节点约束 缩写2 项目.

Actions Status

稳定[email protected] (英语):0.28.3 (中文(简体) )

有问题吗? 跟我们聊聊吧!

访问 libgit2.org (英语) 加入我们.

维护者

泰勒·昂-瓦内克 @twwanek (英语) 以吨计的帮助 伟大的贡献者来啊!

校友维护者

蒂姆·布兰延 @tbranyen (英语), (中文(简体) ), 约翰·海利 @johnhaley81 (英语), (中文(简体) ), 马克斯·克普 @maxkorp (英语), (中文(简体) ), 史蒂夫・史密斯 @ 顺序列表, (中文(简体) ), 迈克尔·鲁滨逊 @ codeof 兴趣,以及 尼克·卡伦 时间轴:

API文档.

http://www.nodegit.org/ (中文(简体) )

开始吧.

节点Git 将工作在大多数系统外 没有本地 依赖性.

npm install nodegit

如果您收到libstdc++的错误, 通常在 在Travis-CI上,你可以通过升级到最新的 libstdc++-4.9. (英语).

在乌本图:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install libstdc++-4.9-dev

在特拉维斯:

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - libstdc++-4.9-dev

在圆CI中:

  dependencies:
    pre:
      - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
      - sudo apt-get update
      - sudo apt-get install -y libstdc++-4.9-dev

如果您收到错误 生命周期脚本 安装前/安装时可能错过 libssl- dev (英语) 在乌本图:

sudo apt-get install libssl-dev

您需要安装在您的 linux 机上的以下库 :

  • 节点
  • libpcreposix 语言
  • 第5节
  • libk5crypto 语录
  • libcom err (英语)

在本地建设时, 您还需要 Kerberos 和 pcre 的开发软件包, 所以这两个公用设施都必须出现在您的机器上 :

  • pcre- 配置
  • krb5 配置

如果安装时仍然遇到问题,请尝试 从源头建楼 说明.

API的例子.

复制寄存器并读取文件 :

var Git = require("nodegit");

// Clone a given repository into the `./tmp` folder.
Git.Clone("https://github.com/nodegit/nodegit", "./tmp")
  // Look up this known commit.
  .then(function(repo) {
    // Use a known commit sha from this repository.
    return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");
  })
  // Look up a specific file within that commit.
  .then(function(commit) {
    return commit.getEntry("README.md");
  })
  // Get the blob contents from the file.
  .then(function(entry) {
    // Patch the blob to contain a reference to the entry.
    return entry.getBlob().then(function(blob) {
      blob.entry = entry;
      return blob;
    });
  })
  // Display information about the blob.
  .then(function(blob) {
    // Show the path, sha, and filesize in bytes.
    console.log(blob.entry.path() + blob.entry.sha() + blob.rawsize() + "b");

    // Show a spacer.
    console.log(Array(72).join("=") + "\n\n");

    // Show the entire file.
    console.log(String(blob));
  })
  .catch(function(err) { console.log(err); });

模拟 git 日志 :

var Git = require("nodegit");

// Open the repository directory.
Git.Repository.open("tmp")
  // Open the master branch.
  .then(function(repo) {
    return repo.getMasterCommit();
  })
  // Display information about commits on master.
  .then(function(firstCommitOnMaster) {
    // Create a new history event emitter.
    var history = firstCommitOnMaster.history();

    // Create a counter to only show up to 9 entries.
    var count = 0;

    // Listen for commit events from the history.
    history.on("commit", function(commit) {
      // Disregard commits past 9.
      if (++count >= 9) {
        return;
      }

      // Show the commit sha.
      console.log("commit " + commit.sha());

      // Store the author object.
      var author = commit.author();

      // Display author information.
      console.log("Author:\t" + author.name() + " <" + author.email() + ">");

      // Show the commit date.
      console.log("Date:\t" + commit.date());

      // Give some space and show the message.
      console.log("\n    " + commit.message());
    });

    // Start emitting events.
    history.start();
  });

更多实例请检查 examples/ 文件夹.

单位测试.

在进行测试之前,您需要在当地建设。 见上.

npm test

版本与发布记录

@figma/nodegit 共发布 8 个版本,首次发布于 2022/02/09;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.28.0-figma.9latest2025/11/2111 个月前
0.28.0-figma.82025/01/161.8 年前
0.28.0-figma.62024/02/012 年前
0.28.0-figma.42023/07/203 年前
0.28.0-figma.32023/04/223 年前
0.28.0-figma.22022/02/114 年前

关于 @figma/nodegit 的常见问题

@figma/nodegit 是什么?

Node.js libgit2 同步本地绑定

如何安装 @figma/nodegit?

在项目目录运行 npm install @figma/nodegit,或使用 pnpm add / yarn add / bun add。

@figma/nodegit 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/figma__nodegit 是否存在。

@figma/nodegit 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@figma/nodegit 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@figma/nodegit 可以商用吗?

@figma/nodegit 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@figma/nodegit 的下载量有多少?

根据 npm 官方下载统计,@figma/nodegit 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,208 次,日均约 107 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@figma/nodegit 还在维护吗?

最新版本 0.28.0-figma.9 发布于 2025/11/21(11 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 1 个;首次发布于 2022/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。