我想知道每次提交Word文档(.doc / .docx)文件时如何使用Git钩子显示消息,让人们知道他们应该提交.xml文件。
答案 0 :(得分:0)
这样的事可能有用:
#!/bin/sh
TMP="$PWD/.tmp"
git status --porcelain | grep '.doc' > "$TMP"
while read -r commitLine; do
added=$(printf '%s\n' "$commitLine" | cut -c1)
test "$added" = "A" && {
commitLine=$(printf '%s\n' "$commitLine" | cut -d\ -f 3-)
list=$(printf "${list}${commitLine}\n")
}
done < "$TMP"
rm "$TMP"
test ! -z "$list" && {
cat << EOF
Doc and Docx files currently staged:
${list}
Please remove them before commit.
EOF
exit 1
}
将其写入.git / hooks / pre-commit
中的可执行文件