【发布时间】:2016-06-25 09:21:23
【问题描述】:
我想知道如何在每次提交 Word 文档 (.doc/.docx) 文件时使用 Git 挂钩显示一条消息,让人们知道他们应该提交 .xml 文件。
【问题讨论】:
标签: git hook githooks git-commit pre-commit-hook
我想知道如何在每次提交 Word 文档 (.doc/.docx) 文件时使用 Git 挂钩显示一条消息,让人们知道他们应该提交 .xml 文件。
【问题讨论】:
标签: git hook githooks git-commit pre-commit-hook
这样的事情可能会奏效:
#!/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 中的可执行文件
【讨论】:
git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\Users\*****\AppData\Local\Temp\bmm1r3ev.b2i cut: the delimiter must be a single character Try 'cut --help' for more information. .git/hooks/pre-commit: line 24: warning: here-document at line 16 delimited by end-of-file (wanted EOF') .git/hooks/pre-commit: 第 25 行:语法错误:文件意外结束 错误完成,见上文。 `