【问题标题】:Git hooks to display a message everytime someone commits a .doc file每当有人提交 .doc 文件时,Git 挂钩以显示一条消息
【发布时间】:2016-06-25 09:21:23
【问题描述】:

我想知道如何在每次提交 Word 文档 (.doc/.docx) 文件时使用 Git 挂钩显示一条消息,让人们知道他们应该提交 .xml 文件。

【问题讨论】:

    标签: git hook githooks git-commit pre-commit-hook


    【解决方案1】:

    这样的事情可能会奏效:

    #!/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 行:语法错误:文件意外结束 错误完成,见上文。 `
    • @Theologie 如果您的 cygwin 环境没有正确实现 POSIX,我无能为力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 2015-12-31
    • 2020-09-11
    • 2016-07-16
    • 2020-05-11
    • 2016-04-02
    • 1970-01-01
    相关资源
    最近更新 更多