Git remote/shared pre-commit hook

后端 未结 6 1366
失恋的感觉
失恋的感觉 2020-11-28 06:42

With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on al

6条回答
  •  醉梦人生
    2020-11-28 07:24

    I create a new file: pre-commit-hook.sh

    #!/usr/bin/env bash
    CHANGES=$(git whatchanged ..origin)
    
    if [ ! -z "${CHANGES}" ]; then
        echo "There are changes in remote repository. Please pull from remote branch first."
        exit 1;
    fi
    
    exit 0;
    

    And this is how I commit to Git:

    bash pre-commit-hook.sh && git commit -m ""
    

提交回复
热议问题