git 如何跨git存储库共享文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1540879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:11:14  来源:igfitidea点击:

How to share files across git repositories?

git

提问by tbeseda

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 is this situation best handled with multiple editors of multiple projects?

我在不同服务器上的子域中有多个应用程序每个应用程序都有自己的 git 存储库。每个应用程序使用多个共享文件。本质上,我的回购重叠。多个项目的多个编辑器如何最好地处理这种情况?

采纳答案by mckeed

I would try making all the overlapping parts git submodules.

我会尝试使所有重叠的部分git submodules

回答by Pete

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

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 updateand you had local unpushed changes on master branch.

这将引导您完成具有子模块的超级项目,从超级项目中编辑子模块并将其推回原位。它还显示了一个危险,如果您运行 agit submodule update并且您在 master 分支上有本地未推送的更改,则无声地覆盖更改。

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 updatein 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.

具体来说,在某个地方你有一个共享文件夹“文件夹”——你需要从所有 git 项目中删除它,但在某处创建一个新的 git repo,将当前内容作为初始提交。然后,您将git submodule <repo> folder; git submodule update参与现在将共享它的所有项目。他们都能够将更改推送到共享存储库,并且能够拉下彼此的更改。

回答by Peter

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.

听起来您应该对公共元素进行分区,以便有明确的区别,然后使用子模块。确保将公共部分清楚地分开,否则最终可能会出现无法维护的混乱局面。

回答by Xiaodong Qi

You could also use the git-subrepotool. The wiki page is linked. It is basically an improved version of submoduleand subtree.

您也可以使用git-subrepo工具。维基页面已链接。它基本上是submoduleand的改进版本subtree