Sometimes I find monorepo https://github.com/babel/babel/blob/master/doc/design/monorepo.md 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[1 /a/39195334/5532169][2 https://github.com/npm/npm/issues/2974]. 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.
目前,我使用本指南 https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/从 GitHub 将包与 monorepo 的其余部分分开,即
git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
Npm 可以轻松安装存储库,但我发现很难合并任何上游更改。
以前有人这样做过吗?任何想法?
实际上,我认为我错过了一些东西 - 合并上游更改并不像我想象的那么难,因为 git subtree split 是确定性的,即它会为相同的子树拆分生成相同的 SHA1,无论该过程重复多少次。
所以这是我的解决方案:
- 克隆单一存储库
-
将默认分支(master)重命名为其他名称,例如上游
git checkout master
git branch -m upstream
-
从 monorepo 中拆分子目录
git checkout upstream
git subtree split -P <subdirectory path> -b master
现在我们有一个主分支,其中仅包含与子目录路径相关的提交。
(选修的)设置 master 分支的远程并将其推送到 GitHub。
现在,如果上游 monorepo 添加了一些更改:
-
检查上游分支并拉取更改
git checkout upstream
git pull
-
再次分裂
git subtree split -P <subdirectory path> -b upstream-patch
检查修订图,您将看到新分支(upstream-patch)与master相关。
gitk master upstream-patch
-
现在只需将新分支合并到master
git checkout master
git merge upstream-patch
手动解决任何合并冲突。
-
(选修的)git 推送
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)