如何分叉monorepo的一部分并仍然能够合并上游提交

如何分叉monorepo的一部分并仍然能够合并上游提交

本文介绍了如何分叉monorepo的一部分并仍然能够合并上游提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候我在GitHub上找到 monorepo 由多个npm软件包组成,我想对其进行一些修改并在我的项目中使用它.但是npm从git子目录安装软件包比从git仓库安装软件包要难得多.由于我要进行自己的修改,所以我想知道如何设置自己的git存储库,以便npm易于安装,并且我可以合并上游更改.

Sometimes I find monorepo on GitHub that consists of multiple npm packages, which I would like to make some modification and use it in my projects. But it's much harder for npm to install package from a git subdirectory than to install from a git repository. Since I would make my own modification, I wonder how can I set up my own git repository so that it is easy for npm to install, and for me to merge upstream changes.

当前,我使用了本指南(来自GitHub),将软件包与monorepo的其余部分(即

Currently, I used this guide from GitHub to split the package from the rest of the monorepo, i.e.

git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME  BRANCH-NAME

Npm可以轻松安装存储库,但是我发现很难合并任何上游更改.

Npm can install the repo easily, but I find it difficult to merge any upstream change.

有人做过吗?有什么主意吗?

Has anyone done this before? Any idea?

推荐答案

实际上,我认为我错过了一些事情-合并上游更改并不像我想的那么难,因为git子树拆分是确定性的,即它会为相同的子树拆分,无论该过程重复多少次.

Actually, I think I missed something - merging upstream changes is not as hard as I thought, because git subtree split is deterministic i.e. it produces the same SHA1 for the same subtree split, no matter how many times the process is repeated.

这是我的解决方案:

  1. 克隆monorepo
  2. 将默认分支(主节点)重命名为其他名称,例如上游

  1. Clone the monorepo
  2. Rename the default branch (master) to something else e.g. upstream

git checkout master
git branch -m upstream

  • 从monorepo拆分子目录

  • Split the subdirectory from the monorepo

    git checkout upstream
    git subtree split -P <subdirectory path> -b master
    

    现在我们有了一个master分支,那里只有与子目录路径有关的提交.

    Now we have a master branch sitting there with only commits related to the subdirectory path.

    (可选)设置master分支的远程并将其推送到GitHub.

    (optional) Set the remote for master branch and push it to GitHub.

    现在,如果上游monorepo添加了一些更改:

    Now if the upstream monorepo added some changes:

    1. 检出上游分支并提取更改

    1. Checkout the upstream branch and pull the changes

    git checkout upstream
    git pull
    

  • 再次拆分

  • Split again

    git subtree split -P <subdirectory path> -b upstream-patch
    

    检查修订图,您将看到新分支(上游补丁)与master相关.

    Check the revision graph, you will see that the new branch (upstream-patch) is related to master.

    gitk master upstream-patch
    

  • 现在只需将新分支合并到master

  • Now simply merge the new branch to master

    git checkout master
    git merge upstream-patch
    

    手动解决任何合并冲突.

    Manually resolve any merge conflicts.

    这篇关于如何分叉monorepo的一部分并仍然能够合并上游提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 09-03 03:33