I would like to be prevented† when staging‡ in a git
repo if the changes I am about to commit contain a certain string (say, @todo
or @hack
).
Can someone show me how to achieve this?
† or warned.
‡ or when committing.
A simple pre-commit hook that checks if the string '@todo' is being added could look like:
#!/bin/sh . git-sh-setup # for die if git-diff-index -p -M --cached HEAD -- \ | grep '^+' \ | grep @todo; then die Blocking commit because string @todo detected in patch fi
If this is the content of .git/hooks/pre-commit
and is executable, any patch that adds the string @todo
will be rejected.
For a more general and thorough solution to this, take a look at Git Confirm:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With