I have this pre-commit hook in .git/hooks/pre-commit
#!/bin/bash
for file in `git diff --name-only`
do
if [[ $file =~ /pom\.xml$ ]]; then
exec < /dev/tty
read -p "Committing $file is often a mistake; are you sure you want to do that? (Y/[N]): " ans
exec <&-
if [[ $ans =~ ^[Yy]$ ]]; then
echo proceeding rashly with commit...
else
echo aborting commit, O prudent one.
exit 1
fi
fi
done
When I use github for mac (GUI client) to commit, it shows this error:
.git/hooks/pre-commit: line 5: /dev/tty: Device not configured
aborting commit, O prudent one.
(1)
It works on command line. But I hope to get the GUI client to work. Any ideas? Thanks!
Your gui client does not provide a tty or any other way of getting input from the user during hooks. So this is not possible. I see two solutions to this problem:
git reset HEAD^
.