Ich habe einen Git-Post-Commit-Hook in meinem Repo. Ich möchte diesen Hook manchmal überspringen.
Um den Pre-Commit-Hook zu überspringen, weiß ich, dass ich das –no-verify-Flag verwenden kann, während ich so übergebe
git commit -m "message" --no-verify
Dies überspringt jedoch nicht den Post-Commit-Hook.
Ist es möglich, den Post-Commit-Hook zu überspringen? Wenn ja, wie geht das?
Von dem Dokumentation:
-n –no-verify Diese Option umgeht die Pre-Commit- und Commit-msg-Hooks. Siehe auch Githooks[5].
Daher überspringt dieses Flag den Post-Commit-Hook nicht. Es scheint keine einfache, saubere Möglichkeit zu geben, dieses Flag zu überspringen. Für einen One-Shot-Betrieb; Sie könnten den Hook einfach deaktivieren und nach Ihrem Commit wieder aktivieren:
chmod -x .git/hooks/post-commit # disable hook
git commit ... # create commit without the post-commit hook
chmod +x .git/hooks/post-commit # re-enable hook
Es ist möglich. Folgendes würde ich für Linux und Bash tun:
#!/bin/bash
# parse the command line of the parent process
# (assuming git only invokes the hook directly; are there any other scenarios possible?)
while IFS= read -r -d $'' ARG; do
if test "$ARG" == '--no-verify'; then
exit 0
fi
done < /proc/$PPID/cmdline
# or check for the git config key that suppresses the hook
# configs may be supplied directly before the subcommand temporarily (or set permanently in .git/config)
# so that `git -c custom.ignorePostCommitHookc=<WHATEVER HERE> commit ...` will suppress the hook
if git config --get custom.ignorePostCommitHook > /dev/null; then
exit 0
fi
# otherwise, still run the hook
echo '+---------+'
echo '| H O O K |'
echo '+---------+'
.
5139800cookie-checkGit Skip-Post-Commit-Hookyes