简体   繁体   English

如果从不贡献上游,git子树简化?

[英]git subtree simplifications if never contributing upstream?

What optimisations exist (including even alternatives to git subtree) if you wish to include a subproject in your main project but never contribute changes upstream? 如果您希望在主项目中包含子项目但从不在上游进行更改,那么存在哪些优化(甚至包括git子树的替代方法)?

Actual use case: I am embedding Ghost into an existing express.js website, eg into lib/Ghost. 实际用例:我将Ghost嵌入到现有的express.js网站中,例如嵌入到lib / Ghost中。 I will need to make a few hacks to it, the type they would not want contributed upstream anyway. 我需要对它进行一些攻击,无论如何他们不希望上游贡献的类型。 Any normal contributing to the Ghost project would be done via a typical forking on GitHub, instead of from within my other project. Ghost项目的任何正常贡献都将通过GitHub上的典型分支完成,而不是来自我的其他项目。

Therefore after the initial embedding of Ghost into my project, the only things happening would be the occasional local source code change, plus sometimes fetching from upstream for updates from their master branch. 因此,在将Ghost初始嵌入到我的项目中之后,唯一发生的事情是偶尔的本地源代码更改,有时还会从上游获取来自其主分支的更新。

In such a scenario, is git subtree still a suitable approach, and if it is then are there either any gotchas or simplifications which would apply, due to this need to never contribute upstream? 在这种情况下,git子树仍然是一种合适的方法,如果它是,那么是否存在任何可能适用的问题或简化,因为这种需要永远不会贡献上游? And would it therefore also be possible to have the main TryGhost/Ghost repository as my subtree upstream, rather than first forking Ghost and then having the fork as the project's upstream? 因此,是否有可能将主要的TryGhost / Ghost存储库作为我的子树上游,而不是首先分配Ghost然后将fork作为项目的上游?

Subtree sounds like a really good fit to me. 子树听起来非常适合我。

If you're making any local changes at all, I think subtree is a better fit over submodules. 如果您正在进行任何本地更改,我认为子树比子模块更适合。

  1. Anyone cloning your project won't need to run additional commands like they would with submodules. 克隆项目的任何人都不需要像子模块那样运行其他命令。
  2. Any changes you make will be made directly to your copy of the sub-project and won't need to be pushed to a public repository for others to access like they would with submodules in order for people to sync those changes. 您所做的任何更改都将直接发送到您的子项目副本,而不需要将其推送到公共存储库以供其他人访问,就像他们使用子模块一样,以便人们同步这些更改。
  3. Pulling from up-stream is a cinch, and if other people working on your project don't have git subtree it won't matter (they just won't be merging or splitting upstream). 从上游拉出来是很容易的,如果在你的项目上工作的其他人没有git子树,那就无所谓了(他们只是不会合并或分裂上游)。

The only downside I can think of is that you have a full copy of the sub-projects in your repository, but unless it's an enormous project that's optional for your super-project who cares about that? 我能想到的唯一缺点就是你在你的存储库中有子项目的完整副本,但除非它是一个巨大的项目,对你的超级项目是否可选?

  • You should not need to make a branch for the subproject, just: 您不需要为子项目创建分支,只需:

     git subtree add --prefix Ghost --squash -m "Adding Ghost." https://github.com/TryGhost/Ghost.git master 

    You can freely make changes from that point on and completely ignore the fact that it originally came from Ghost depot. 您可以从该点开始自由地进行更改,并完全忽略它最初来自Ghost软件仓库的事实。 You don't even need to add the remote as you can tell from my example above. 从上面的示例中可以看出,您甚至不需要添加遥控器。

  • If you pull often, you may want to create the remote. 如果你经常拉,你可能想要创建遥控器。

     git remote add ghost https://github.com/TryGhost/Ghost.git git subtree pull --prefix=Ghost --squash -m "Updating Ghost." ghost master 
  • Finally, even if you decide at some later point that you want to contribute back upstream, to a fork or wherever, it's really simple for you to just split out the parts relevant to the sub-project into a branch and then just push the changes from that branch to the fork repository. 最后,即使您稍后决定要向上游,分支或任何地方做出贡献,您只需将与子项目相关的部分拆分为分支,然后推送更改即可从该分支到fork存储库。

     git subtree split -p Ghost -b Ghost-contrib-br --rejoin # this should switch to the branch with only the ghost files git push <remote-contrib-repo> 

    Note: I didn't use --squash because the history will be only what you modified since the add or last --rejoin 注意:我没有使用--squash因为历史记录将只是自add或last --rejoin以来修改的--rejoin

    --rejoin is kind of a lame hack which commits back to your super-project so the split command knows the best starting point for the next split. --rejoin是一种蹩脚的黑客,它会提交回你的超级项目,因此split命令知道下一次拆分的最佳起点。 In the future I think this will be managed from a new section the .git/config (I may even make it so myself). 在未来,我认为这将通过.git / config的新部分进行管理(我甚至可以自己制作)。

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

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