在进行 git hook 时有没有办法获取用户 y/n 选项?例如,在运行预提交
ruff
linter 检查后,用户可能决定不添加建议的更改。
如果是这样,有没有办法通过添加
pre-commit
选项来通过 shell would you like to continue with the commit?
文件(在 .git/hooks 中)本身继续进行更改?
我知道 vscode 中有一个
No verify commit
选项,但这不是我要找的。
你的预提交挂钩可能是这样的:
#!/bin/bash
# 获取用户输入
read -p "would you like to continue with the commit? [Y/n] " answer
# 判断用户输入
if [[ $answer =~ ^[Yy]$ || $answer == "" ]]; then
exit 0 # 退出并允许提交
else
echo "Commit aborted."
exit 1 # 退出并阻止提交
fi