我应该将 Autotools 生成的哪些文件保留在版本控制存储库中?
我是 autotools 的新手,正在开发一个 C 项目。我想将我的项目添加到 git 存储库。我需要在版本控制系统中跟踪哪些由自动工具生成的文件,哪些应该被忽略?
I am new to autotools and I am working on a C project. I want to add my project to a git repository. Which files generated by the autotools I need to track in my version control system and which should be ignored?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应将任何未经手工编辑的文件置于版本控制之下。这意味着版本控制系统应该忽略任何生成的文件。我基本上只将以下内容置于版本控制之下:
configure.ac
Makefile.am
AUTHORS
、NEWS
等Makefile.am
为了解决 Scharron 提出的“准备安装”版本的问题,有些人在项目的根目录,称为
bootstrap
或autogen.sh
,当您签出新副本时运行一次。您可以在我的一个项目中看到一个示例 在这里。对于更简单的项目,您的 autogen.sh 实际上只需要包含一行:尽管有些人更喜欢在 autogen 末尾自动运行
./configure
.sh。为什么不在版本控制中跟踪所有生成的文件?因为它们的内容取决于您构建的机器、生成它们的自动工具的版本以及月相。任何时候任何这些更改,生成的自动工具文件都会更改,并且您的提交中将收到大量垃圾。
此外,任何为了构建代码而从版本控制中检查代码的人都应该安装适当的开发工具,因此您真的不需要担心人们因为缺少自动工具而遇到麻烦。
VonC 所说的关于带有
configure
文件来生成Makefile
的 C 项目对于源代码发行版(.tar .gz
文件,当您键入make dist
时获得的文件),但不一定用于从版本控制中新鲜检出的副本。You should not keep any files under version control that are not hand-edited. That means any generated file should be ignored by the version control system. I basically put only the following under version control:
configure.ac
Makefile.am
AUTHORS
,NEWS
etc.Makefile.am
in subdirectoriesTo address the point of having a "ready-to-install" version brought up by Scharron, some people include a script in the project's root directory, called
bootstrap
orautogen.sh
, that you run once when you check a fresh copy out. You can see an example in one of my projects here. For a simpler project, yourautogen.sh
really only needs to consist of one line:although some people prefer to run
./configure
automatically at the end ofautogen.sh
.Why not track all the generated files in version control? Because their contents depend on the machine you are building on, the version of autotools you generated them with, and the phase of the moon. Any time any of these changes, the generated autotools files will change, and you will get a lot of junk in your commits.
Also, anyone who checks your code out of version control in order to build it should be expected to have proper development tools installed, so you really don't need to worry about people running into trouble because of missing autotools.
What VonC says about C projects coming with a
configure
file to generate theMakefile
s is true for source code distributions (the.tar.gz
file that you get when you typemake dist
) but not necessarily for freshly checked out copies from version control.注意:我同意 ptomato 的 答案,并将此答案保留为社区 Wiki。
这对于源代码分发是有意义的,但您的项目可能不是这样。
出于开发目的,ptomato的答案更有意义。
所有 C 项目通常都附带一个配置文件,能够生成用于编译的实际 Makefile。
因此,当您考虑自动工具链时,我建议对配置文件之前生成的所有文件进行版本控制,因为它们通常是一次性生成操作。
这意味着任何拥有您的版本项目副本的人都可以立即开始:
因此,虽然通常是这样,但您不应该对任何生成的文件进行版本控制,您可以存储这些文件,特别是如果其他读者来自该文件项目可以:
Note: I agree with ptomato's answer, and leave this answer as Community Wiki.
It makes sense for source code distributions, but your project may not be one.
For development purpose, ptomato's answer makes more sense.
All the C projects generally come with a configure file able to generate the actual Makefile used for the compilation.
So when you consider the autotool chain, I would recommend versioning all files generated up to the configure file, as they are normally a one-time generation operation.
That means anyone with a checked out copy of your version project can immediately start:
So, while it is generally true, you shouldn't version any generated files, you could store those, especially if the other reader from that project can:
The
ed
in the flow chart is likely a placeholder for the text editor used to modify or create theconfigure.ac
andMakefile.am
files.In the context of Autotools, these files are written by a developer to specify the configuration and build instructions for the software.
ed
is actually one of the standard text editors in Unix and Unix-like systems and represents the concept of editing these files manually.In a graphical representation of the Autotools workflow, showing an editor like
ed
emphasizes that theconfigure.ac
andMakefile.am
files are typically handcrafted rather than generated by the Autotools themselves.autoscan
can be used to generate a preliminaryconfigure.ac
, which is then edited by a developer using a text editor (ed
in this case) to fine-tune the configuration process.一般来说,您不应该在存储库中保留任何生成的文件(否则您会看到更改并且必须提交它们/还原它们)。
但是,如果您想将“准备安装”版本添加(=标记)到您的存储库,我建议保留配置和 Makefile 文件。它们是安装所需的,无需自动工具即可工作。
Generally, you should not keep any generated files on a repository (else you would see changes and have to commit them / revert them).
However, if you want to have "ready-to-install" version added (= tagged) to your repository, I would recommand to keep configure and Makefile files. They are the one needed for an install, that should work without autotools.