How would I write a pre-merge hook in Git?

前端 未结 3 1142
终归单人心
终归单人心 2020-12-01 07:34

The question says it all. Is there a way to perform an action before a merge? I\'m guessing there\'s a way to make use of a pre-commit hook, but I\'m not quite

3条回答
  •  不思量自难忘°
    2020-12-01 07:46

    Another nice workaround would be to add a shell script, call it like you want, then add these lines to the script:

    git() {
        if [ "$1" == "merge" ]; then
            echo "seems to work like a charme"
        fi
        command git "$@"
    }
    
    git "$@"
    

    Then make an

    alias git="./my-pre-merge-script.sh"
    

    Then you are good to go. You just added your own pre-merge hook. I know, that you do not have access to whatever arguments git would pass to a real pre-merge hook, but you can prepare files or whatever you want to prepare for merge now; I personally am very happy with this approach: I spent 2 or 3 whole days to find something for pre-merge, then I had to go with the pre-commit-msg which I did not find accurate enough for my needs. This solves all my problems. Hope this helps anybody in the future.

提交回复
热议问题