Registry / devops / git-log-parser

git-log-parser

JSON →
library1.2.1jsnpmunverified

git-log-parser is a Node.js library designed to execute the `git log` command and stream its output as structured JavaScript objects. Released in 2015 with its latest stable version 1.2.1, it provides a programmatic interface to extract commit metadata such as commit hashes, author and committer details (name, email, date), subject, and body. It handles the conversion of configuration objects into command-line arguments for `git log` using `argv-formatter` and spawns a `child_process` to execute the `git` command. While functional, the package has seen no updates since its last release, indicating an abandoned status. Developers should be aware of its reliance on an external `git` installation and the need for stream processing libraries (like `through2` or `stream-to-array`) to consume its output as an array. Its primary differentiator is simplifying the interaction with `git log` by abstracting command-line argument formatting and providing parsed object streams.

npm install git-log-parser
INSTALL
IMPORT
SIG · GIT-LOG-PARSER
G
git-log-parser
devopsjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

log
import log from 'git-log-parser';
import { parse } from 'git-log-parser';
The package exports a default object containing the `parse` method and `fields` property.
log
const log = require('git-log-parser');
CommonJS usage for older Node.js environments or projects.
log.fields
import log from 'git-log-parser'; console.log(log.fields);
import { fields } from 'git-log-parser';
`fields` is a property of the default exported `log` object, not a named export.

This example demonstrates how to use git-log-parser to retrieve commits from the last 24 hours, collect them into an array, and print details of the latest commit. It also includes basic error handling for common issues like 'git' not found.

import log from 'git-log-parser'; import toArray from 'stream-to-array'; async function getRecentCommits() { try { // Parse commits from the last 24 hours const commitsStream = log.parse({ before: new Date(Date.now() - 24 * 60 * 60 * 1000) }); // Collect all commits into an array const commits = await toArray(commitsStream); console.log(`Found ${commits.length} commits from the last 24 hours.`); if (commits.length > 0) { console.log('--- Latest Commit ---'); const latest = commits[0]; console.log(`Subject: ${latest.subject}`); console.log(`Author: ${latest.author.name} <${latest.author.email}>`); console.log(`Date: ${latest.author.date.toISOString()}`); console.log(`Short SHA: ${latest.commit.short}`); } } catch (error) { console.error("Failed to parse git log:", error.message); if (error.code === 'ENOENT' && error.syscall === 'spawn git') { console.error('Make sure Git is installed and available in your system PATH.'); } } } getRecentCommits();
Debug
Known issues
breakingThe package has been abandoned since 2016. It may not be compatible with newer versions of Node.js, `git` CLI changes, or modern stream APIs without significant issues. Use with caution in new projects.
fix
Consider using actively maintained alternatives or be prepared to fork and update the library for compatibility.
affects: >=1.2.1
gotchaThis library relies on the `git` command-line tool being installed and accessible in the system's PATH. If `git` is not found, the parser will fail.
fix
Ensure `git` is installed on the system where the Node.js application runs and is included in the environment's PATH variable.
affects: >=1.0.0
gotchaThe `parse` method returns a Node.js Readable Stream. To get an array of commit objects, you need to pipe it to a consumer like `stream-to-array` or manually process the stream chunks.
fix
Install `stream-to-array` (`npm install stream-to-array`) and use `await toArray(log.parse(...))` to convert the stream to an array of commits.
affects: >=1.0.0
Errors
Common errors & fixes
Error: spawn git ENOENT
The `git` command is not found in the system's PATH.
fix
Install Git on your system and ensure its executable path is added to your environment variables. For Windows, reinstall Git and select the option to add Git to PATH. For Linux/macOS, ensure Git is installed (e.g., `sudo apt-get install git` or `brew install git`).
TypeError: Cannot read properties of undefined (reading 'parse') (or similar for 'fields')
Incorrect import statement or module not found.
fix
If using ESM, ensure you are using `import log from 'git-log-parser';` (default import). If using CommonJS, use `const log = require('git-log-parser');`. Verify the package is correctly installed.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
stream-to-arrayoptionalCommonly used to collect the output stream of commit objects into a JavaScript array for easier processing.
Agent activity
2 hits · last 30 days
node
2
Resources
git-log-parser — npm install git-log-parser · libregistry