Last active
October 31, 2023 22:43
-
-
Save gorbatova/4728fb36bc4fcfc1e9740a41ea635179 to your computer and use it in GitHub Desktop.
Add timestamp and branch name to GIT commit message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Go to .git/hooks/ directory | |
# Step 2: Rename "commit-msg.sample" to "commit-msg" (CLI: mv commit-msg.sample commit-msg) | |
# Step 3: Replace the existing code in a "commit-msg" file with the following code | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
TIMESTAMP=$(date +"%D %T") | |
DESCRIPTION=$(git config branch."$NAME".description) | |
echo "$TIMESTAMP — $NAME"': '$(cat "$1") > "$1" | |
if [ -n "$DESCRIPTION" ] | |
then | |
echo "" >> "$1" | |
echo $DESCRIPTION >> "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment