简体   繁体   中英

Good way to share code in .git/hooks/pre-commit

Is there a good way I can share the code in .git/hooks ?

The only thing I can think of is to create command line tools, and call those tools from each script in .git/hooks/*

You can either:

  • version your pre-commit script in your own repo ( git add --chmod=+x ) and describe in the README of said repo what a user needs to do to activate it (for instance a symbolic link from .git/hooks/pre-commit to your script)
  • or setup a git repo template , provided all the users of that repo have access to a common shared path.

Create a git repo on github. Clone it to your fs. Symlink the hooks files to .git/hooks/* , or better yet, use:

git config core.hooksPath .githooks

which will tell .git to use the .githooks folder in your project to look up the hooks, instead of .git/hooks

My suggestion: https://githooks.com/

There are a few ways to manage hooks. I ended up creating one for myself and made it public weeks ago: https://github.com/lovato/hooks4git

In my approach, there are no global scripts (like other tools or even git properly configured). Once the tool is installed and activated on your repo, you commit your scripts along with your code.

In any approach, you can link files to an external repo, and have all your scripts shared, without actually needing to touch .git/hooks folder directly.

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