commit-stream

中文文档
3.0.2发布于 2026/11/03MITTypeScriptES Module零依赖构建来源已验证

Turn a git log into a stream of commit objects

原始使用文档

commit-stream

Turn a git log into a stream of commit objects

NPM

API

commitStream([defaultGithubUser, defaultGithubProject])

Returns an object stream that you can pipe a stream of newlines from the output of git log to. The output of the stream is a series of objects, each representing a commit from the log.

Intended to be used on a standard log format (not a simplified one using one of the simplifying --format options) but it will also process change stats if you git log --stat.

Typical usage:

import { spawn } from 'node:child_process'
import { createInterface } from 'node:readline'
import { pipeline } from 'node:stream/promises'
import commitStream from 'commit-stream'

const { stdout } = spawn('git', ['log'])
const commits = []

await pipeline(
  createInterface({ input: stdout, crlfDelay: Infinity }), // break up by newline characters
  commitStream('rvagg', 'commit-stream'),
  async (source) => {
    for await (const commit of source) commits.push(commit)
  }
)
// commits is an array of objects

Commit object properties:

  • sha: the full commit sha
  • author: an object representing the author of the commit
    • name: the name of the committer
    • email: the email of the committer
  • authors: a list of such objects representing the authors of the commit, supporting multiple authors through Co-authored-by:
  • authorDate: a string representing the date of the original commit by the author (never change)
  • commitDate: a string representing the date of the last change of the commit
  • summary: the one-line summary of the commit
  • description: the free-form text content of the summary, minus specific metadata lines
  • reviewers: an array containing objects with name and email properties if the commit metadata contains reviewers in a Reviewed-By: Foo Bar <baz@boom> format.
  • changes: if --stat data is included in the git log, an object containing change stats:
    • files: the number of files changed
    • insertions: the number of new lines inserted
    • deletions: the number of old lines removed
  • prUrl: a URL pointing to a pull-request where this change was made if the commit metadata contains a PR-URL: https://github.com/user/project/pull/XX line. Note that whatever proceeds the PR-URL: string will be collected in this property; one exception being that if a shortened #XX version is found and you have supplied defaultGitHubUser and defaultGitHubProject arguments to the constructor then a full GitHub pull-request will be reconstituted in its place.
  • ghUser, ghProject, ghIssue: if a proper GitHub pull request is found for the prUrl property (including shortened #XX ones), these properties will be added to point to the original user, project and issue (pull-request) for this change, as extracted from the URL. Also, if a commit message line ends with (#XX) as is done with green-button merges, this will be used.

License

commit-stream is Copyright (c) 2015 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

版本与发布记录

commit-stream 共发布 19 个版本,首次发布于 2015/07/22;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.2latest2026/11/03今天
3.0.12026/11/021 天前
3.0.02026/11/021 天前
2.2.72026/11/021 天前
2.2.62026/11/021 天前
2.2.52026/11/021 天前

关于 commit-stream 的常见问题

commit-stream 是什么?

把一个 git log 转换成提交对象流

如何安装 commit-stream?

在项目目录运行 npm install commit-stream,或使用 pnpm add / yarn add / bun add。

commit-stream 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

commit-stream 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

commit-stream 可以商用吗?

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

commit-stream 还在维护吗?

最新版本 3.0.2 发布于 2026/11/03(今天);至今共发布 19 个版本,其中过去 12 个月发布了 10 个;首次发布于 2015/07/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。