简体   繁体   English

git-subtree适合我吗?

[英]Is git-subtree appropriate for me?

I have a 3rd party library included in my project. 我的项目中包含一个第三方图书馆。 It is important that the "subproject" code should be included in the main/parent one, because the objective is when other people makes git pull, they could will download the code with no extra-effort (or minimal). 将“子项目”代码包含在主/父代码中很重要,因为目标是当其他人进行git pull时,他们可以毫不费力(或最少)下载代码。

But I want the possibility to download updates from the library own repo. 但是我希望可以从库自己的存储库中下载更新。

Previously, that library was downloaded directly into his directory and updates were managing by commits in the main project. 以前,该库直接下载到他的目录中,而更新由主项目中的提交来管理。

Now I'm thinking in use git-subtree or git-submodule. 现在我正在考虑使用git-subtree或git-submodule。 Is git-subtree are useful for that purpose. git-subtree是否对这个目的有用。 Is git-submodule better? git-submodule更好吗?

Git subtree. Git子树。

  • Easy for others to get. 容易被他人获得。
  • Avoids complications if you DO want to make changes to the library. 如果您确实想对库进行更改,则可以避免麻烦。
  • Use the squash option to avoid pulling in massive histories when merging the library. 使用squash选项可以避免合并库时引入大量历史记录。
  • You can merge the library, using the git subtree command, and no one else needs to have support for the command to access and use your repository. 您可以使用git subtree命令合并该库,并且没有其他人需要该命令的支持才能访问和使用您的存储库。
  • Changes made in your repository inadvertently to the library are no problem, and simply to split out if you want to contribute them. 在存储库中无意中对库所做的更改都没有问题,并且如果您要贡献它们,只需将其分开即可。

Almost always, it's best to use the package manager of whatever language you're using to include third-party code, pinned to a specific version. 几乎总是,最好使用您所使用的任何语言的程序包管理器来包含固定在特定版本上的第三方代码。 If you don't have a package manager, pull the code from a specific commit/tag of the third party repo in a build script into a git-ignored subfolder. 如果您没有程序包管理器,则将代码从构建脚本中第三方仓库的特定提交/标记中拉到git忽略的子文件夹中。

But to answer your question specifically, there are a lot of resources out there to compare subtree and submodule. 但是要具体回答您的问题,有很多资源可以比较子树和子模块。 There are pros and cons each way. 每种方式都有优点和缺点。 I could give you links, but I'd just be copying and pasting from my search. 我可以给您链接,但是我只是从搜索中复制和粘贴。 I would suggest that for code you're not directly changing as part of your project, a submodule is fine, because you probably don't want the history of the library code in your project. 我建议对于代码来说,您不应该直接在项目中更改它,而是使用子模块,因为您可能不希望项目中的库代码历史记录。

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

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