commit-name-generator
v1.0.2
Published
Generate Conventional Commit messages from Git changes
Maintainers
Readme
Commit Message Generator
A TypeScript command-line tool that analyzes Git changes and suggests a Conventional Commit message.
It can inspect staged and unstaged changes and open the generated message in VS Code's Git commit editor.
Features
Detects changes in the current Git repository
Suggests Conventional Commit messages
Recognizes feature, fix, test, documentation, and dependency changes
Supports staged and unstaged changes
Opens the suggested message in VS Code for editing
Works through npx or a global npm installation
Requirements
Node.js 18 or newer
Git
VS Code when using the --edit option
Installation
Install the package globally:
npm install --global @tahakoko/commit-name-generator
Run the package without installing it:
npx @tahakoko/commit-name-generator
If the package is published without an npm scope, use commit-name-generator instead of @tahakoko/commit-name-generator.
Usage
Stage the files you want to commit:
git add .
Generate a commit message:
commit-name-generator
Example output:
Changes detected. Suggested commit: feat: add new functionality
Open the message in VS Code
Use the --edit option:
commit-name-generator --edit
Edit the message if needed, save the file, and close the editor. Git completes the commit after the editor closes.
Analyze unstaged changes
Use --all to analyze changes that have not been staged:
commit-name-generator --all
Combine --all and --edit to stage all detected changes and open the generated message in VS Code:
commit-name-generator --all --edit
CLI Options
Option
Short option
Description
--all
-a
Analyze unstaged changes
--edit
-e
Open the generated message in VS Code's Git editor
--help
-h
Display command help
--version
-V
Display the installed version
Examples
Generate a message from staged changes:
git add src/index.ts commit-name-generator
Open the generated message in VS Code:
git add . commit-name-generator --edit
Analyze all current changes and commit them through VS Code:
commit-name-generator --all --edit
Possible suggestions include:
feat: add new functionality fix: resolve application issue test: update test coverage docs: update documentation chore: update project dependencies chore: update project files
Local Development
Clone the repository:
git clone https://github.com/tahakourani-t/commit-message-generator.git cd commit-message-generator
Install the dependencies:
npm install
Run the CLI directly from TypeScript:
npm run dev
Build the package:
npm run build
Run the tests:
npm test -- --run
Link the package globally for local testing:
npm link commit-name-generator --help
Preview the files that will be included in the npm package:
npm pack --dry-run
Publishing
Log in and confirm your npm account:
npm login npm whoami
Build and test the package:
npm run build npm test -- --run
Publish the package:
npm publish --access public
For a future patch release:
npm version patch npm publish --access public
Use npm version minor for new backward-compatible features and npm version major for breaking changes.
Conventional Commit Format
Generated messages follow this structure:
type(scope): description
Common types:
feat: a new feature
fix: a bug fix
docs: documentation changes
test: test changes
refactor: code restructuring without a feature or bug fix
chore: maintenance, tooling, or dependency changes
Troubleshooting
Error: Not a Git Repository
Run the command inside a Git repository:
git init
No Staged Changes Found
Stage your changes and try again:
git add . commit-name-generator
Alternatively, analyze unstaged changes:
commit-name-generator --all
VS Code Does Not Open
Make sure the code command is available:
code --version
On macOS, open the VS Code Command Palette and choose Shell Command: Install 'code' command in PATH.
On Windows, rerun the VS Code installer and enable the option to add VS Code to PATH.
Repository
https://github.com/tahakourani-t/commit-message-generator
Author
Taha Kourani
License
MIT
