在另一个项目中使用 Git 存储库中的项目
我正在构建一个框架,以使一些常见功能(数据库连接)更容易,并希望在另一个项目中使用它。我总是可以复制并粘贴它,但我正在努力并不断扩展它。每当我在 Git 存储库中进行提交时,让它复制更新后的自身会容易得多。
我可以使用 Git 自动更新其他项目中的框架吗?还是必须寻找其他解决方案?
I have a framework I am building to make some common functions (database connection) easier and would like to use it in another project. I could always just copy and paste it, but I am working on it and expanding it constantly. It would be much easier to just have it copy its updated self over whenever I do a commit in my Git repo.
Could I use Git to automatically update the framework in my other project or will I have to find another solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 git 子树或 git 子模块。
上次我检查时,子模块有一些重大问题(但我听说它们在最近的版本中得到了一些改进)。请参阅此处了解详细信息:Git 子模块工作流程
简而言之:
子树是常规的 Git 分支,使用特殊的合并策略进行合并,将其所有文件放入主机存储库工作副本的子目录中。除了合并策略(仅在创建合并提交时才重要)之外,Git“子树”是一个完全正常的 Git 分支。
优点:
-s subtree
命令行选项(请参阅 此处了解完整的工作流程)。仅当您执行子树拉取时才需要记住子树。缺点:
子模块是主机存储库内的 Git存储库。
优点:
缺点:
免责声明:我对子模块有偏见。亲自尝试看看哪种方法更适合您的工作流程。
Use either git subtrees or git submodules.
Last time I've checked, submodules had some major issues (but I've heard that they were improved a bit in recent versions). See here for details: Git submodules workflow
In short:
Subtrees are regular Git branches, merged with special merge strategy, which puts all their files into a subdirectory of the host repository working copy. Aside of the merge strategy (which matters only when merge commit is created), Git "subtree" is a perfectly normal Git branch.
Pros:
-s subtree
command line option (see here for the full workflow). You need to remember about subtree only when you do the subtree pull.Cons:
Submodules are Git repositories inside the host repository.
Pros:
Cons:
Disclaimer: I'm biased against submodules. Try and see for yourself, what approach is better for your workflow.
git 子模块。
在不同地方更新时您会遇到一些问题,但应该可以解决。
git-submodules.
You will have a few issues with updating in different places, but it should work out.