wukong-gitlog-cli

Advanced Git commit log exporter with Excel/JSON/TXT output, grouping, stats and CLI.


Features


What’s new


Installation

Clone and install dependencies:

git clone https://github.com/tomatoboy/wukong-gitlog-cli.git
cd wukong-gitlog-cli
npm install

Install globally to run with a short command (recommended for CLI consumers):

# Install globally from the repo (for development):
npm link
# Or install via npm when published:
npm i -g wukong-gitlog-cli

# Then you can run the CLI globally:
wukong-gitlog-cli --help

Usage

wukong-gitlog-cli [options]

Command-line options:

Output files are written to an output/ directory in the current working directory.

Tip: Use --out-parent or --out-dir ../output to write outputs into the parent folder’s output/ to avoid accidentally committing generated files to your repository.


Gerrit support

Use the --gerrit option to include a Gerrit link for each commit. You can provide a template containing `` to place the full commit hash into the URL, for example:

wukong-gitlog-cli --gerrit "https://gerrit.example.com/c/project/+/" --limit 5 --format text

If `` is not present, the CLI will append the commit hash to the prefix with a / separator.

You can also use in the template to reference Gerrit change id. The tool will try to extract a `Change-Id: I...` value from the commit body and replace with it. If it can’t find a Change-Id, the CLI will fall back to using the commit hash.

The Gerrit link will show up in:

Note: --out <file> is the filename only and the directory used to store that file depends on:

For example:

# using globally installed CLI
wukong-gitlog-cli --out parent.json --out-parent
wukong-gitlog-cli --out demo.txt --out-dir ../temp

Examples

Export as text, grouped by month, with Gerrit links:

wukong-gitlog-cli --format text --group-by month --gerrit "https://gerrit.example.com/c/project/+/"

// Resolve numeric change ID using Gerrit API (if available) wukong-gitlog-cli –format text –group-by month –gerrit “https://gerrit.example.com/c/project/+/” –gerrit-api

If your Gerrit requires authentication (HTTP Basic or token), use --gerrit-auth:

# HTTP Basic: username:password
wukong-gitlog-cli --format text --gerrit "https://gerrit.example.com/c/project/+/" --gerrit-api <GERRIT_API_BASE_URL> --gerrit-auth "username:password"

# Token (Bearer)
wukong-gitlog-cli --format text --gerrit "https://gerrit.example.com/c/project/+/" --gerrit-api <GERRIT_API_BASE_URL> --gerrit-auth "MYTOKEN"

Export to Excel with stats and Gerrit URLs:

wukong-gitlog-cli --format excel --stats --gerrit "https://gerrit.example.com/c/project/+/"

Export raw JSON:

wukong-gitlog-cli --json --out commits.json

Export text to a custom directory (parent output folder):

wukong-gitlog-cli --out-dir ../output --format text --limit 5 --out custom1.txt

Quick demo (npm scripts)

We provided a few convenient npm scripts to quickly run common scenarios. Run them from the project root:

# show help
npm run cli:help

# simple text export (commits.txt in ./output)
npm run cli:text-demo

# Excel export with stats (commits.xlsx + commits.txt in ./output)
npm run cli:excel-demo

# JSON export (commits.json in ./output)
npm run cli:json-demo

# Gerrit text export demo
npm run cli:gerrit-demo
# Gerrit Change-Id demo (use commit Change-Id to build Gerrit URLs when present)
npm run cli:gerrit-changeid-demo

If you prefer to write output outside the project (e.g., a parent output/ folder), we also provide npm scripts that run with --out-parent:

# text export to parent `output/`
npm run cli:text-demo-parent

# excel export to parent `output/`
npm run cli:excel-demo-parent

Example text output (from npm run cli:text-demo):

Hash       | Author             | Date                 | Message
---------------------------------------------------------------------------------------------------------------------
c5bdf9d4   | tom                | 2025-11-25           | feat: 🎸 增加output目录

ea82531   | tom                | 2025-11-25           | feat: 🎸 init

741de50   | tom                | 2025-11-25           | first commit

Example JSON output (from npm run cli:json-demo):

[
  {
    "hash": "c5bdf9d4f52f39bd7d580318bafc8ba4b6c129bc",
    "author": "tom",
    "email": "",
    "date": "2025-11-25 17:24:32 +0800",
    "message": "feat: 🎸 增加output目录"
  }
  /* truncated... */
]

Example JSON output including changeId/gerrit when --gerrit uses `` (if present in commit):

[
  {
    "hash": "Iabc...",
    "author": "tom",
    "email": "",
    "date": "2025-11-25 17:24:32 +0800",
    "message": "feat: add feature",
    "body": "feat: add feature\n\nChange-Id: Iabcd123456789",
    "changeId": "Iabcd123456789",
    "gerrit": "https://gerrit.example.com/c/project/+/Iabcd123456789"
  }
]

Notes & Developer Info

Suggested .gitignore snippet (to avoid accidentally committing generated files):

# ignore commit exports
output/
custom-output/

Contributing

PRs are welcome — add tests and keep changes modular. If you add new CLI flags or new fields in commit records, please update this README accordingly.


License

MIT