替代git子模块

问题描述 投票:0回答:1

我经常为自己的用法编写一些库,我想在不同的项目中使用它们。我希望有可能编辑库并使更改在使用库的所有项目中都有效。到现在为止,我总是要复制和粘贴。

我试过子模块但是根据git submodules reference似乎有许多垮台。

这种依赖管理有更好的可能性吗?这是什么最好的做法?

git version-control dependencies git-submodules
1个回答
0
投票

有两种情况可以与不同项目的库一起使用。假设repoA中的库和repoB是项目存储库之一。

Situation 1: The libraries only work for you own (only manage libraries in repoA)

您可以直接将本地repoA中的库添加到本地repoB

在本地repoB - >右键单击projectB的解决方案 - >添加 - >现有项目 - >将库从本地repoA添加到本地repoB - > commit - > push。

现在无论在哪里(在本地repoA或本地repoB)您更改了库,它实际上更改了本地repoA中的库,因此本地repoA和本地repoB中的库始终同步。

Situation 2: other developers also need the libraries in projectB (manage libraries both in repoA and repoB)

如果其他开发人员也需要使用这些库,您还应该管理repoB中的库。通常使用的方式是git submodulegit subtree

由于你已经尝试过子模块,我只会显示git subtree如下:

  • 将库(假设在masterrepoA分支中)添加到repoBgit subtree add --prefix=repoB <URL for repoB> master
  • 如果repoA有一些变化,请从repoArepoB进行更改: git subtree pull --prefix=repoB <URL for repoB> master
  • 如果在qazxsw poi中对库进行更改,则将更改推送到qazxsw poi: qazxsw poi
© www.soinside.com 2019 - 2024. All rights reserved.