简体   繁体   English

Git,拉入另一个存储库的一部分

[英]Git, pull in part of another repository

Say there are two repositories X and Y with a file structure like below. 假设有两个存储库X和Y,文件结构如下所示。

X-+
  |- /A
  |- /B
  |- /C

Y-+
  |- /E
  |- /F
  |- /G

I know it's possible to pull X into Y and git will merge the files. 我知道可以将X拉入Y并且git将合并文件。 Is it possible to pull directory B into directory F of repository Y? 是否可以将目录B拉入存储库Y的目录F? I'm guessing it isn't because git doesn't track directories. 我猜这不是因为git不跟踪目录。 Is it possible to achieve this with git in some other way? 是否有可能以其他方式使用git实现这一点?

You can do this with symlinks and git submodules: http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/ 您可以使用符号链接和git子模块执行此操作: http//chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/

Note you still have to pull in the whole project tree as a submodule so if you are trying to save space, this won't help and you'll need some other solution. 请注意,您仍然必须将整个项目树作为子模块拉入,因此如果您尝试节省空间,这将无济于事,您将需要一些其他解决方案。

For example (this assumes a *nix system), inside project Y: 例如(这假设是一个* nix系统),在项目Y中:

mkdir .include
git submodule add git@mygithost:X .include/X
ln -sf .include/X/B F

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

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