You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create following file in your repository folder .git/hooks/pre-receive
#!/usr/bin/env bash# Pre-receive hook that will block commits with messges that do not follow regex rule
commit_msg_type_regex='feat|fix|refactor|style|test|docs|build'
commit_msg_scope_regex='.{1,20}'
commit_msg_description_regex='.{1,100}'
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_description_regex})\$"
merge_msg_regex="^Merge branch '.+'\$"
zero_commit="0000000000000000000000000000000000000000"# Do not traverse over commits that are already in the repository
excludeExisting="--not --all"
error=""whileread oldrev newrev refname;do# branch or tag get deletedif [ "$newrev"="$zero_commit" ];thencontinuefi# Check for new branch or tagif [ "$oldrev"="$zero_commit" ];then
rev_span=`git rev-list $newrev$excludeExisting`else
rev_span=`git rev-list $oldrev..$newrev$excludeExisting`fiforcommitin$rev_span;do
commit_msg_header=$(git show -s --format=%s $commit)if! [[ "$commit_msg_header"=~ (${commit_msg_regex})|(${merge_msg_regex}) ]];thenecho"$commit">&2echo"ERROR: Invalid commit message format">&2echo"$commit_msg_header">&2
error="true"fidonedoneif [ -n"$error" ];thenexit 1
fi
⚠ make .git/hooks/pre-receive executable (unix: chmod +x '.git/hooks/pre-receive')
Conventional Commit Messages
See how a minor change to your commit message style can make a difference.
Tip
Have a look at git-conventional-commits , a CLI util to ensure these conventions, determine version and generate changelogs
Commit Message Formats
Default
Merge Commit
Follows default git merge message
Revert Commit
Follows default git revert message
Inital Commit
Types
feat
Commits, that adds or remove a new featurefix
Commits, that fixes a bugrefactor
Commits, that rewrite/restructure your code, however does not change any API behaviourperf
Commits are specialrefactor
commits, that improve performancestyle
Commits, that do not affect the meaning (white-space, formatting, missing semi-colons, etc)test
Commits, that add missing tests or correcting existing testsdocs
Commits, that affect documentation onlybuild
Commits, that affect build components like build tool, ci pipeline, dependencies, project version, ...ops
Commits, that affect operational components like infrastructure, deployment, backup, recovery, ...chore
Miscellaneous commits e.g. modifying.gitignore
Scopes
The
scope
provides additional contextual information.Breaking Changes Indicator
Breaking changes should be indicated by an
!
before the:
in the subject line e.g.feat(api)!: remove status endpoint
Description
The
description
contains a concise description of the change.This commit will...
orThis commit should...
.
) at the endBody
The
body
should include the motivation for the change and contrast this with previous behavior.Footer
The
footer
should contain any information about Breaking Changes and is also the place to reference Issues that this commit refers to.BREAKING CHANGES:
followed by space or two newlines. The rest of the commit message is then used for this.Examples
Git Hook Scripts to ensure commit message header format
Click to expand
commit-msg Hook (local)
pre-receive Hook (server side)
.git/hooks/pre-receive
.git/hooks/pre-receive
executable (unix:chmod +x '.git/hooks/pre-receive'
)References
The text was updated successfully, but these errors were encountered: