简体   繁体   English

如何设置git以将另一个仓库的文件夹检出到我的仓库子目录中?

[英]How to setup git to checkout a folder of another repo into my repo subdirectory?

In our project, one person is writting plain SCSS, and other people are working on Rails app. 在我们的项目中,一个人正在编写普通的SCSS,其他人正在使用Rails应用程序。 I regulary have to copy the SCSS from the simple repo into the Rails asset pipeline. 我经常不得不将SCSS从简单的仓库中复制到Rails资产管道中。 The copy is exact. 该副本是准确的。 So I would like to know how to setup git so that I could do it on a regular basis? 因此,我想知道如何设置git以便可以定期执行此操作? (as convenient as possible) (尽可能方便)

Well, I guess git submodules is the feature you're looking for. 好吧,我想git子模块就是您要寻找的功能。 See the git documentation at https://git-scm.com/book/en/v2/Git-Tools-Submodules 请参阅https://git-scm.com/book/en/v2/Git-Tools-Submodules上的git文档

If I sound a little hesitant, it's because I've always thought it was a bit odd to pull in dependencies with the source control software; 如果我有点犹豫,那是因为我一直认为用源代码控制软件引入依赖关系有点奇怪。 if you could automate this through your build tools I think it might be a more natural solution. 如果您可以通过构建工具自动执行此操作,那么我认为这可能是更自然的解决方案。 But if doing it as a git operation is the way to go for you, I'd look at the above. 但是,如果将它作为git操作进行是适合您的方法,那么我会看上面的内容。

UPDATE 更新

Follow-up question from comments: Can a submodule be set up for just a sub-folder of the other project? 评论中的后续问题:是否可以仅为另一个项目的子文件夹设置子模块?

So we have project A 所以我们有项目A

projectA/
    stuff/
    other-stuff/
    shared-stuff/

and project B 和项目B

projectB/
    more-stuff/
    unrelated-stuff/

and we want projectA/shared-stuff to show up also as projectB/shared-stuff/ and we're talking about how to do this with submodules. 并且我们希望projectA/shared-stuff也显示为projectB/shared-stuff/ ,我们正在谈论如何使用子模块来实现。

I don't know that a submodule can be any more specific than "embed this commit of that repo". 我不知道子模块可以比“嵌入该回购的提交”更具体。 But one suggestion would be to split the shared code into its own repo 但是一个建议是将共享代码拆分成自己的仓库

shared-stuff/

Then add shared-stuff as a submodule of both project A and project B 然后将共享的东西添加为项目A和项目B的子模块

projectA repo       | shared-stuff repo |  projectB repo
==================================================================
/                   |                   |  /
    stuff/          |                   |      more-stuff/
    other-stuff/    |                   |      unrelated-stuff/
    (shared-stuff)--> /                 <--    (shared-stuff)

Of course because submodule mappings are contained within the repo using the submodule, the folder names (or locations in the parent projects' trees) don't have to match... 当然,因为子模块映射包含在使用子模块的存储库中,所以文件夹名称(或父项目树中的位置)不必匹配...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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