我如何将一个文件夹从一个Git存储库共享到另一个?

问题描述 投票:2回答:2

我有两个共享数据库模式的项目[git repos],但实际上只有一个项目包含DDL SQL文件。我知道我可以添加一个包含SQL的子树,但这将接管所有代码和所有内容-我需要的只是带有SQL文件的目录,因此我可以在第二个项目中创建模式以使用H2进行测试。我真的不希望尝试手动同步它们[无效]-因此我希望将项目1中的/sql文件夹简单地链接到项目2中。

我也无法在Git中创建任何新的存储库。

git git-subtree
2个回答
2
投票

1。 Submodule

使用Git的子模块,您只能将整个存储库链接到另一个存储库中。因此,一种方法是将整个/sql目录分为一个单独的存储库,并将其作为子模块链接到两个存储库中。

在这种情况下,对链接存储库文件的更改将被推送到源存储库。

2。 Subtree

但是还有一个subtree可能会允许您所需。但我从未使用过,所以您必须尝试一下。

例如查看this page

# Clone the target repo
git clone [email protected]:jclouds/jclouds.git
cd jclouds

# Add the source repository as a remote, and perform the initial fetch.
git remote add -f sourcerepo [email protected]:jclouds/jclouds-labs-openstack.git

# Create a branch based on the source repositories' branch that contains the state you want to copy.
git checkout -b staging-branch sourcerepo/master

# Here's where the two approaches diverge.
# Create a synthetic branch using the commits in `/openstack-glance/` from `sourcerepo`
git subtree split -P openstack-glance -b openstack-glance

# Checkout `master` and add the new `openstack-glance` branch into `/apis/openstack-glance/`. At this point, the desired result will have been achieved.
git checkout master
git subtree add -P apis/openstack-glance openstack-glance

# Clean up by removing the commits from the `openstack-glance` branch and the `sourcerepo` remote.
git branch -D openstack-glance staging-branch
git remote rm sourcerepo

在这种情况下,对链接的子树或目录的更改不会被推送回源存储库,但是我想您所需要的应该没事。


0
投票

Git中没有本机功能可以满足您的需求。我想到两个“技巧”:

© www.soinside.com 2019 - 2024. All rights reserved.