Can Git hook scripts be managed along with the repository?

前端 未结 11 1220
独厮守ぢ
独厮守ぢ 2020-11-22 14:00

We\'d like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored

11条回答
  •  长情又很酷
    2020-11-22 14:38

    Theoretically, you could create a hooks directory (or whatever name you prefer) in your project directory with all the scripts, and then symlink them in .git/hooks. Of course, each person who cloned the repo would have to set up these symlinks (although you could get really fancy and have a deploy script that the cloner could run to set them up semi-automatically).

    To do the symlink on *nix, all you need to do is:

    root="$(pwd)"
    ln -s "$root/hooks" "$root/.git/hooks"
    

    use ln -sf if you're ready to overwrite what's in .git/hooks

提交回复
热议问题