开发者

How to share files across git repositories?

开发者 https://www.devze.com 2022-12-08 06:03 出处:网络
I have several applications across sub domains on various servers Each application has its own git repository. Each application uses several shared files.

I have several applications across sub domains on various servers Each application has its own git repository. Each application uses several shared files. Essentially, my repos overlap. How 开发者_StackOverflow中文版is this situation best handled with multiple editors of multiple projects?


I would try making all the overlapping parts git submodules.


As long as the multiple projects are pushing their changes to the submodule up to the shared location, yeah they can all makes changes to the shared resource. That said, if one of them needs theirs to be 'special' they'll have to branch the submodule.

https://git-scm.com/book/en/v2/Git-Tools-Submodules

This walks you through a super project with submodules, editing the submodule from within the super project and pushing it back up. It also shows the one danger which is silently overwriting changes if you run a git submodule update and you had local unpushed changes on master branch.

Specifically, somewhere you've got a shared folder 'folder' - you'll need to remove this from all the git projects, but create a new git repo somewhere with the current contents as the initial commit. Then you'll git submodule <repo> folder; git submodule update in all the projects which will now share it. They'll all be able to push changes up to the shared repo, and will be able to pull down each other's changes.


It sounds like you should partition the common elements so that there's a clear distinction, then use submodules. Make sure you clearly separate the common pieces, otherwise you'll likely end up with an unmaintainable mess.


You could also use the git-subrepo tool. The wiki page is linked. It is basically an improved version of submodule and subtree.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号