简体   繁体   English

GIT-从另一个数据库创建的新存储库-正在合并吗?

[英]GIT - New repository created from another — merging?

I have created a new git repository based on another. 我已经基于另一个创建了一个新的git存储库。 They will slowly be diverging from each other. 他们将慢慢彼此分离。

But for now, is it ok to add a remote to the other repository I merged from in order to bring in commits? 但是现在,可以将远程添加到我合并的其他存储库中以引入提交了吗?

It seems weird, but it works. 看起来很奇怪,但是有效。

If I understand your question correctly, you have two repositories, let's call them original and fork . 如果我正确理解了您的问题,则您有两个存储库,我们称它们为originalfork In order to create fork , you ran: 为了创建fork ,您运行了:

git clone path/to/original fork

Now you're doing work in fork , want to pull some of those changes into original , and are wondering if it's OK to add a remote in order to pull from fork into original : 现在,您正在使用fork进行工作,想将其中的一些更改拉入original ,并想知道是否可以添加一个遥控器以便从fork插入到original

cd path/to/original
git remote add fork path/to/fork
git remote update
git pull fork master

Yes, it's perfectly fine to do this. 是的,这样做非常好。 A remote just says that you want to be able to track what's going on in another repository, and possibly pull or push changes. 遥控器只是说您希望能够跟踪另一个存储库中发生的事情,并可能拉出或推送更改。 Now, you cannot push changes to a non-bare repo (if both original and fork have working copies, then you can't push between them). 现在,您不能将更改推送到非裸仓库(如果originalfork都具有工作副本,则无法在它们之间推送)。 But it's perfectly fine to add remotes for any repo you want, and pull changes in from branches in that repo, and even do the same on the other side afterwards. 但是,可以为所需的任何存储库添加远程服务器,并从该存储库的分支中提取更改,然后在另一侧执行相同操作,这也很好。

There's effectively no difference between merging from the repo you cloned from and merging from a branch within your own repository. 从您克隆的仓库中合并与从您自己的存储库中的分支合并之间实际上没有区别。 What matters is how the branches (or repositories) have diverged. 重要的是分支(或存储库)如何分开。

It's unclear from your question what the content in question is - you say "slowly diverging". 从您的问题尚不清楚所涉及的内容是什么-您说的是“缓慢分歧”。

If the original begins to contain things that you don't want in your new repository, then merging is a bad idea. 如果原始文档开始包含新存储库中不需要的内容,那么合并是一个坏主意。

If on the other hand, everything you do to the original should be propagated to the new one, then by all means, merge. 另一方面,如果您对原始内容所做的一切都应传播到新的内容,那么一定要合并。 (But I'm guessing you won't ever want to merge in the other direction.) (但是我想您永远不会在另一个方向上合并。)

Finally, if these repositories represent two projects based on a common template, and you want to make changes to that template and share them between the two, the best thing to do would be to make a third repository which is only the template, and merge from that into each of the two, but never directly between the two. 最后,如果这些存储库代表一个基于公共模板的两个项目,并且您想要对该模板进行更改并在两者之间共享,那么最好的办法是制作第三个存储库,即模板,然后合并从那个变成了两个,但从来没有直接在两个之间。

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

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