Git 和打包:防止打包文件妨碍的常见模式?
对于我开发的最后一个 Python 项目,我使用 git 作为版本控制系统。现在是开发周期的时间,我应该开始向 Beta 测试人员发送软件包(在我的例子中,它们是 .deb 软件包)。
为了构建我的包,我需要一些额外的文件(copyright
、icon.xpm
.setup.py
、setup.xpm)。 cfg
、stdeb.cfg
等...),但是我希望将它们与程序的源代码分开,因为可能会使用源代码为其他平台准备软件包,拥有这些软件包是没有意义的Debian 特定的文件挥之不去。
我的问题:有没有标准方法/最佳实践?在我的谷歌漫游中,我绊倒了几次(包括这里是这样)在 git-buildpackage 套件,但我不确定这就是我正在寻找的东西,因为这似乎是为从上游存储库下载 tar.gz 的打包程序所考虑的。
我认为实现我想要的一个可能的方法是在 git 存储库上有一个分支,我在其中保存打包文件,但是这个分支也应该能够在没有我的情况下“查看”主分支上的文件每次都需要手动将master合并到打包分支中。但是:
- 我不知道这是否是一个好主意/应该这样做的方式
- 虽然我怀疑它可能涉及一些 git symbolic-ref 魔法,但我不知道如何做我想象的事情
感谢您的帮助,提前感谢您的宝贵时间!
For the last python project I developed, I used git as versioning system. Now it's that time of the development cycle in which I should begin to ship out packages to the beta testers (in my case they would be .deb packages).
In order to build my packages I need a number of extra files (copyright
, icon.xpm
. setup.py
, setup.cfg
, stdeb.cfg
, etc...) but I would like to keep them separate from the source of the program, as the source might be used to prepare packages for other platforms, and it would make no sense having those debian-specific files lingering around.
My question: is there a standard way/best practice to do so? In my google wanderings I stumbled a couple of times (including here on SO) on the git-buildpackage suite, but I am not sure this is what I am looking for, as it seems that is thought for packagers that download a tar.gz from an upstream repository.
I thought a possible way to achive what I want would be to have a branch on the git repository where I keep my packaging-files, but this branch should also be able to "see" the files on the master branch without me having every time to manually merge the master into the packaging branch. However:
- I don't know if this is a good idea / the way it should be done
- Although I suspect it might involve some
git symbolic-ref
magic, I have no idea how to do what I imagined
Any help appreciated, thanks in advance for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您为什么要将它们排除在源代码控制之外?它们是生成最终构建输出的输入的一部分!您绝对不想失去对它们的跟踪,并且您可能希望在继续开发应用程序时跟踪它们如何随时间变化。
您最可能想要做的是为所有这些发行版特定文件创建一个子目录,例如
./debian
或./packaging/debian
并将它们提交到那里;您可以有一个 makefile 或一些这样的文件,当您在该目录中运行它时,将所有文件复制到创建包所需的位置,这样您就可以了!why would you want to keep those out of the source control? They are part of the inputs to generate the final, built output! You definately don't want to lose track of them, and you probably want to keep track of how they change over time, as you continue to develop your application.
What you most likely want to do is create a subdirectory for all of these distribution specific files to live, say
./debian
or./packaging/debian
and commit them there; You can have a makefile or some such that, when you run it in that directory, copies all of the files where they need to be to create the package, and you'll be in great shape!最后我选择了一个带有 makefile 的分支,这样我的打包过程现在看起来像这样:
如果您有兴趣,您可以找到完整的 makefile 这里(免责声明:这是我的第一个 makefile,所以很可能它不是您见过的最好的 makefile)。
简而言之,“窍门”的核心就在
get-source
指令中,它就是git archive
命令的使用,它接受分支的名称作为参数,并生成包含该分支的源代码的 tarball。这是片段:希望这对其他人也有帮助!
At the end I settled for a branch with a makefile in it, so that my packaging procedure now looks something like:
If you are interested you can find the full makefile here (disclaimer: that is my first makefile ever, so it's quite possible it's not the best makefile you will ever see).
In a nutshell, the core of the "trick" is in the
get-source
directive, and it is the use of thegit archive
command, that accepts the name of a branch as an argument and produces a tarball with the source from that branch. Here's the snippet:Hope this helps somebody else too!
您可以将额外的文件放在单独的存储库中(以便它们也具有版本控制),并使用
子模块
在源代码存储库中使用它。You can have the extra files in a separate repo ( so that they are versioned too) and use
submodules
to use it in your source code repo.