# @figma/nodegit 中文文档

规范地址：https://npmcn.com/package/%40figma/nodegit/

版本：0\.28\.0-figma\.9
npm 元数据更新时间：2026-09-10T19:34:04.145Z
中文译文更新时间：2026-11-14T18:00:24.917Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40figma/nodegit
原文对照：https://npmcn.com/package/%40figma/nodegit/?lang=original
项目主页：http://nodegit.org/
源码仓库：https://github.com/nodegit/nodegit

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：248 kB，84 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>= 16
- 运行依赖：9 个
- 首次发布：2022-02-08T20:07:07.324Z
- 最新版本发布：2025-11-20T18:25:47.244Z
- 近 30 天下载量：3208（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 1 个）

## 中文简介

Node.js libgit2 同步本地绑定

## 安装

```sh
npm install @figma/nodegit
```

也可以使用：`pnpm add @figma/nodegit`、`yarn add @figma/nodegit`、`bun add @figma/nodegit`

## README

# 节点吉特

> 节点约束 [缩写2](http://libgit2.github.com/) 项目.

[![Actions Status](https://github.com/nodegit/nodegit/workflows/Testing/badge.svg)](https://github.com/nodegit/nodegit/actions)

**稳定[libgit2@v0.28.3 (英语)](mailto:libgit2@v0.28.3):0.28.3 (中文(简体) )**

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

访问 [libgit2.org (英语)](http://slack.libgit2.org/) 加入我们.

## 维护者

泰勒·昂-瓦内克 [@twwanek (英语)](http://twitter.com/twwanek) 以吨计的帮助 [伟大的贡献者](https://github.com/nodegit/nodegit/contributors)来啊!

### 校友维护者

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

## API文档.

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

## 开始吧.

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

```bash
npm install nodegit
```

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

在乌本图:

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

在特拉维斯:

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

在圆CI中:

```yaml
  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 配置

如果安装时仍然遇到问题,请尝试 [从源头建楼](http://www.nodegit.org/guides/install/from-source/) 说明.

## API的例子.

### 复制寄存器并读取文件 :

```javascript
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 日志 :

```javascript
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/` 文件夹.

## 单位测试.

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

```bash
npm test
```

## 常见问题

### @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 和提交记录判断。

