简体   繁体   English

需要将新存储库连接到现有目录中的目录

[英]need to connect a new repository to a directory in an existing one

I have a repository, that contains a directory: 我有一个存储库,其中包含一个目录:

repository/libs/somelibrary

this directory is now to be separated into a different repository but, while this process is going on, my team will keep commiting changes to this directory. 现在,该目录将被分离到另一个存储库中,但是在执行此过程的同时,我的团队将继续提交对该目录的更改。
So I created a new repository - somelibrary - which will contain the original files like so: 因此,我创建了一个新的存储库somelibrary将包含原始文件,如下所示:

- somelibrary
   - src
       - the original directory structure
   - package.json
   - Gruntfile.js

What i'm looking is for an easy way to keep that src directory in sync with the commits in the original repository: 我正在寻找的是一种使该src目录与原始存储库中的提交保持同步的简单方法:

somelibrary/src/** => repository/libs/somelibrary/**

Is there a way to do this? 有没有办法做到这一点?

This seems to be a good application case for subtree merging . 这似乎是子树合并的一个很好的应用案例。 First add the original repository as a remote to somelibrary : 首先将原始repository添加为某个repository的远程somelibrary

git remote add original repository

Then fetch it: 然后获取它:

git fetch original

Then initiate a merge of the original repository into somelibrary : 然后将原始存储库合并到somelibrary库中:

git merge -s ours --no-commit original/master

Only import the correct subtree into the pending commit: 仅将正确的子树导入到挂起的提交中:

git read-tree --prefix=src/ -u original/master:libs/somelibrary

Then finalize the commit with git commit 然后用git commit完成git commit

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

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