This repository contains two Git hook scripts designed to automate versioning and changelog generation based on commit messages. These scripts are intended to be used as Git hooks to streamline your development workflow.
- If the commit message contains a version tag (
ver:X.Y.Z
orver:X.Y
), it uses that version, creates a Git tag with the specified version and optionally pushes the tag to the remote repository. - If no version tag is found, it generates a version number based on the latest tag, the number of commits since that tag, the commit timestamp, and the commit hash.
- If no version information is available, it falls back to the version specified in a
VERSION
file.
Additionally, it generates a CHANGELOG.md
and RELEASE_NOTES.md
file based on the commit history.
To use these scripts as Git hooks, follow these steps:
-
Clone or download the scripts:
- Download the
post-commit
script from this Gist.
- Download the
-
Place the script in your Git hooks directory:
- Navigate to your Git repository.
- Copy the scripts into the
.git/hooks/
directory:cp post-commit .git/hooks/
-
Make the script executable:
- Ensure the scripts have executable permissions:
chmod +x .git/hooks/post-commit
- Ensure the scripts have executable permissions:
-
Test the hook:
- Make a commit with a version tag in the message (e.g.,
ver:1.2.3
orver:1.2
) to see the scripts in action. - Check the
VERSION
,CHANGELOG.md
, andRELEASE_NOTES.md
files for updates.
- Make a commit with a version tag in the message (e.g.,
To trigger version tagging, include a version tag in your commit message using the format:
ver:X.Y.Z
Example:
Added new feature. ver:1.2.3
If no version tag is found in the commit message, the commit-msg
script will generate a version number in the format:
<latest-tag>-<commits-since-tag>-<datestamp>-<last-commit-short-hash>
Example:
v1.0.0-2-250221-abc1234
The scripts automatically generate:
CHANGELOG.md
: A list of commits since the last tag.RELEASE_NOTES.md
: A formatted release note with the version and changelog.
- To prevent pushing tags to the remote repository, comment the following line in the
post-commit
script:# git push origin "$VERSION"
- Modify the versioning logic in the
post-commit
script to suit your project's needs.
These scripts are provided under the MIT License. Feel free to use and modify them as needed.