简体   繁体   中英

git pre-commit hook file

I tried to add the pre-commit hook file gitlab server side. I know pre-commit hook is client side hook. I just want to add the pre-commit hook file in all the project's .git/hooks folder.

What I tried:- I edited all the pre-commit.sample file in my gitlab server machine and created the new project. But I did not found that edited sample hook file in my local (windows) after cloned the repo.

Is there any way to add the pre-commit hook in all the project's git folder by server side? Because we have more than 500 projects.

You can't do that, from the documentation at https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks

It's important to note that client-side hooks are not copied when you clone a repository. If your intent with these scripts is to enforce a policy, you'll probably want to do that on the server side

This is the fundamental trade-off with client-side hooks: they can't be centrally configured.

You could add the hook script(s) you want to the work tree, along with a script that you run in the root of the work tree to copy the scripts into .git/hooks . Then if individual users want the hooks, they can run the script. (Assuming they don't have some exotic setup where .git isn't in the root of the work tree.)

But no, you can't make it automatic that cloning your repo causes arbitrary code you selected to be run at times of your specification on someone else's computer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM