简体   繁体   中英

git post-commit hooks

I've got two git project repos that have two or three files in common.

Something like this:

Project A ------> helper_functions

Project B ------> helper_functions

I'm wondering if there's an accepted method to "share" these common helper files between the repos, so that I don't have to maintain separate copies in both repos.

Would something like a post commit hook that would update the helper_functions in Project B when the helper_functions from Project A are updated? Or is there a more seamless method for ensuring both projects have the latest and greatest version of the helper_functions file and that the file automatically gets included in any package of the project?

Thanks for any ideas or resources on an accepted way to deal with this.

Also, I wanted to add that both of these projects have collaborators, so it would ideally be automatic, so we're all on the same page without having to use soft links or aliases.

Some people might say this is overkill for just a few files, but to me this sounds like a good case for using git's support for submodules. Basically, you would create a new repository called helper_functions , and add that to each of the existing repositories as a submodule with:

git submodule add git://foo/bar/helper_functions.git helper_functions

There are a few subtleties to do with working with submodules, however, so it would be worth doing some reading first. I like the description in the git manual as a starting point, but there are plenty of other nice explanations, eg that from Pro Git .

I wouldn't create hooks to commit and push the submodule, however - I think it's better to carefully consider when you want to update the version of the submodule that's committed in the main repository. What I have found quite useful, though, is to use a commit-submodule script that makes sure you push your submodule changes before committing a new submodule version in the repository.

I would use a submodule but would recommend the use of "git slave" to work with any updates to the shared repository.

The alternative is the use of subtree.

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