简体   繁体   English

保持Git fork的最佳方法

[英]Best way to maintain a Git fork

Company ACME keeps a product X that we extend and customize. 公司ACME保留了我们扩展和定制的产品X. They have made their git repository visible to us, but we can't write to it. 他们让我们的git存储库可见,但我们不能写它。 ACME is using their own internal Git server with Gitolite. ACME正在使用他们自己的内部Git服务器和Gitolite。

Our developers want to write to it, so we need a local copy. 我们的开发人员想要写它,所以我们需要一个本地副本。 However, I'd be nice to keep the Commit history from Company ACME. 但是,我很高兴保留公司ACME的提交历史记录。 Is there a way to do it? 有办法吗? Also, how should I go about updating our code with code from Company ACME? 另外,我应该如何使用公司ACME的代码更新我们的代码? We are using Github Enterprise. 我们正在使用Github Enterprise。

The way I was thinking loses the history from Company ACME. 我的思维方式失去了公司ACME的历史。

  1. Clone repository X into a Staging folder. 将存储库X克隆到Staging文件夹中。 Keep this repository up to date from Company ACME. 从ACME公司保持此存储库最新。
  2. Create new repository Y for our use. 创建新的存储库Y供我们使用。
  3. Create branch in Repository Y for "Original" code. 在存储库Y中为“原始”代码创建分支。 Developers would branch or fork from this. 开发人员会从中分支或分叉。
  4. Manually copy the files from Repository X into "Original" branch of Repository Y. 将文件从Repository X手动复制到Repository Y的“Original”分支。

There must be a best way. 必须有一个最好的方法。 I essentially want to make a local fork and keep it updated while still giving our developers access to commit code. 我本质上想要创建一个本地fork并保持更新,同时仍然允许我们的开发人员访问提交代码。

this is called the "vendor branch" pattern. 这被称为“供应商分支”模式。 (consider adding those SO tags to your post.) (考虑将这些SO标签添加到您的帖子中。)

you can also embed the ACME artefacts in your rep: the original, unchanged ACME code will live on its own (so-called "vendor"-) branch, and will be merged to 'master' or wherever you need it. 您还可以在您的代表中嵌入ACME文件:原始的,未更改的ACME代码将存在于其自己的(所谓的“供应商” - )分支中,并将合并为“主”或任何您需要的地方。

whenever ACME changes code, you checkout the ACME vendor branch and store the updates there, tag with the vendor tag (this eases seeing what versions of ACME are in house), and merge the changes where needed. 每当ACME更改代码时,您都会检查ACME供应商分支并在那里存储更新,使用供应商标签进行标记(这样可以轻松查看内部版本的ACME),并在需要时合并更改。

Edit added : Once you understand this mechanism, take a look at the subtree merge mechanism . 编辑添加 :了解此机制后,请查看子树合并机制

In my opinion you can fork the ACME repository. 在我看来,你可以分叉ACME存储库。 So now you have write access to your forked repository (or local clone). 所以现在您可以对分叉存储库(或本地克隆)进行写访问。

Now you can create a new branch in this local repository to continue your development while still having kept the master branch (or renaming it to whatever suits your needs) linked with the original readonly repository. 现在,您可以在此本地存储库中创建一个新分支,以继续开发,同时仍保留与原始只读存储库链接的主分支(或将其重命名为适合您需要的分支)。

Doing this, whenever you need to update your code to the latest developments made in the ACME repository, you can simply pull their changes from that remote and merge them to your development branch. 这样做,每当您需要将代码更新为ACME存储库中的最新开发时,您只需从该远程处获取更改并将它们合并到您的开发分支。 There is no need to create several copies of that repository. 无需创建该存储库的多个副本。

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

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