A pre-commit hook is added locally to the .git/hooks
folder and is executed before you can add a commit message.
In this script we use expand
and sponge
commands, so you need to have the relevant libraries installed.
To install for Ubuntu,
apt get -y moreutils
Inside .git/hooks
directory, create a file pre-commit
and add the lines in the pre-commit
file below.
- Add the files via VSCode, or
git add -A
- After you type your commit message, the pre-commit script will be executed. It'll change the file and you need to add it back again.