如何使用 git 管理 django 上的分叉可重用应用程序
我正在使用 django 开发一个项目。我正在使用 git 进行版本控制。
我想在项目中使用一些可重用的 django 应用程序,例如 django-mailer。我计划分叉 github 存储库并将其克隆到项目文件夹。但这会将 git 存储库引入另一个存储库中。我也不确定是否需要 fork。
您如何处理类似的情况?有什么最佳实践吗?
I am developing a project using django. I am using git for version controlling it.
I want to use some reusable django apps e.g. django-mailer for the project. I am planning to fork the github repo and clone it to project folder. But that will bring a git repo inside another. I am also not sure if fork is needed or not.
How you are handling similar scenario? Any best practices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 virtualenv (或者更好的 virtualenvwrapper)加上 pip 加上 requiremens.txt 将使您保持环境清洁。
requirement.txt 允许您使用 git repo 作为应用程序源,甚至您可以指定要使用的特定版本/标签/分支。
Using virtualenv (or even better virtualenvwrapper) plus pip plus requiremens.txt will allow you to keep you environment clean.
requirement.txt allow you to use git repo as an app source, and even you can specify a specific version/tag/branch to use.
如果您希望在 Git 存储库中使用 Git 存储库,则应考虑 Git 子模块。 Git 子模块提供了一种方法,可以将单独的 Git 存储库包含在您自己的存储库中,并管理它在代码库中保留的版本。
基本工作流程如下:
django-mailer
文件夹;如果需要,您可以指定一个替代名称,就像使用 git clone 一样。git status
时可以看到是否有需要提交的内容。稍后,如果您需要更新子模块(git 存储库中的 git 存储库),请直接导航到该子模块并执行标准的 git pull origin master 操作。如果有更新,请返回到您的父项目,执行标准的 git add 和 git commit 来提交您的存储库依赖于较新版本的子模块的事实。
现在,如果您稍后将项目克隆到其他地方,默认情况下子模块不会同时拉取它们的代码;您的父项目只存储您的子模块应该位于的提交,而不是它们的实际代码。在这种情况下,您需要使用以下命令初始化并更新子模块:
现在您的子模块也应该有它们的代码。
Git 社区书籍中详细介绍了所有这些内容。 Blip.tv 上还有一个不错的视频,展示了 git 子模块工作流程。
In situations where you want a Git repo inside a Git repo, you should consider Git submodules. Git submodules provide a means for including a separate Git repo inside your own and managing what version it stays at within your code base.
The basic workflow is as follows:
git submodule add
command. For example,git submodule add https://github.com/jtauber/django-mailer.git
will put adjango-mailer
folder in your project; you can specify an alternative name just like you do withgit clone
if desired.git status
that you have something to commit.git commit -m "Your message"
to commit what you've done.Later, if you need to update the submodule (the git repo within your git repo), then navigate into it directly and do the standard
git pull origin master
. If there are updates, go back up into your parent project, do a standardgit add
andgit commit
to commit the fact that your repo depends on a newer version of the submodule.Now, if you later clone your project somewhere else, by default the submodules won't pull their code down at the same time; your parent project just stores which commit your submodules should be at, not their actual code. In this situation, you need to initialize and then update your submodules with the following commands:
Now your submodules should have their code as well.
All of this is detailed in the Git community book. There's also a nice video on Blip.tv showing the git submodule workflow.
我个人使用 buildout + mr.developer,它可以下载 git/mercurial 存储库并将这些应用程序添加到 Eggs 文件夹中。
仅当您想根据自己的需要更新该应用程序时才需要分叉,如果其工作方式正常,则不需要分叉(只需克隆)。如果您不希望其他应用程序更新该应用程序(它可能会崩溃),只需复制/粘贴/or_clone_without_auto_updates/fork即可完成此工作。
要处理存储库中的存储库(初始?)对我来说,最佳实践是使用诸如构建之类的东西,也许结构可以(嗯,它应该)完成这项工作。
PS 我将发布有关构建基础知识的博客文章,如果有兴趣,我可以稍后发送链接。
I personally use buildout + mr.developer which can download git/mercurial repos and adds those apps to eggs folder.
Forking is only required if you want to update that app to your own needs, if its fine how it works, forking is not needed (just clone). If you don't want that app to be updated by others (that it could possibly crash something) simple copy/paste/or_clone_without_auto_updates/fork does the job.
To handle repository within a repository (inception?) the best practice for me is using something like buildout, maybe fabric would (well it should) do the job.
P.S. I'll post blog article about basics of buildout, i could send a link latter on if interested.