Skip to content

Instantly share code, notes, and snippets.

@cm0s
Forked from fgeller/prepare-commit-msg
Created December 18, 2018 22:56
Show Gist options
  • Save cm0s/08f7a2846c58ca03b7de6ff96fb91f74 to your computer and use it in GitHub Desktop.
Save cm0s/08f7a2846c58ca03b7de6ff96fb91f74 to your computer and use it in GitHub Desktop.
prefixes commit message with path of changed files. useful in mono-repo setup
#!/bin/sh
prefixes=$(git diff --cached --name-only | while read f ; do echo "${f%/*}" ; done | sort | uniq)
prefixes_count=$(echo $prefixes | wc -l)
if [ "$prefixes_count" -eq "1" ]; then
sed -i "1s;^;$prefixes: \n;" "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment