Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

版本控制系统

前言

Godot 的目标是做到 VCS 友好,生成的文件大多可读、可合并。

版本控制插件

Godot 旨在对版本控制系统(Version Control System,VCS)友好,并尽量生成可读且可合并的文件。Godot 支持通过插件在编辑器本身中使用 VCS。可以在编辑器中的项目> 版本控制下设置或关闭 VCS。

截至 2023 年 7 月,尚且只有一个 Git 插件可用,但社区可能会创建其他的 VCS 插件。

官方 Git 插件

有一个官方插件可以让你在编辑器中使用 Git。你可以在GitHub找到最新的版本。

最新的更新、文档和源代码可以在Godot iOS插件库找到 Godot iOS plugins repository

从 VCS 中排除的文件

备注

这里列出了 Godot 4.1 及更高版本中应从版本控制中被忽略的文件和文件夹。

Godot 4.0 及更低版本中的版本控制应忽略的文件夹及文件列表与 Godot 4.1 及更高版本 ** 完全 ** 不同。 这点非常重要,因为 Godot 3.x 和 4.0 可能会将敏感凭据存储在 export_presets.cfg 中,而 Godot 4.1 及更高版本不会。

如果你正在使用 Godot 3,请查看本页说明文档的 3.5 版本。

当第一次在编辑器中打开项目时,Godot 会自动创建一些文件和文件夹。 为了避免生成的数据使版本控制仓库膨胀,你应该将它们添加到 VCS 忽略中:

  • .godot/:此文件夹存储各种项目缓存数据。

  • *.translation:这些文件是从 CSV 文件生成的导入后的的二进制翻译文件。

你可以选择在 Godot 项目管理器创建项目时自动生成版本控制元数据。当选择 Git 选项时,将在项目根目录中创建 .gitignore.gitattributes 文件:

在项目管理器的“新建项目”对话框中创建版本控制元数据

在项目管理器的新建项目对话框中创建版本控制元数据

在现有的项目中,选择编辑器顶部的 项目 菜单,然后选择 版本控制 > 生成版本控制元数据。这将与在项目管理器中执行的操作一样创建相同的文件。

在 Windows 上使用 Git

大多数 Git for Windows 客户端都将 core.autocrlf 设置为 true。可能会导致部分文件错误地被 Git 标记为已修改,因为这些文件的行尾被自动从 LF 转换成了 CRLF。

最好将此选项设置为:

git config --global core.autocrlf input

使用项目管理器或编辑器创建版本控制元数据时,会使用 .gitattributes 文件自动强制使用 LF 行尾,因此无需更改 Git 配置。

Git LFS

Git LFS (Large File Storage) is a Git extension that allows you to manage large files in your repository. It replaces large files with text pointers inside Git, while storing the file contents on a remote server. This is useful for managing large assets, such as textures, audio files, and 3D models, without bloating your Git repository.

备注

When using Git LFS you will want to ensure it is setup before you commit any files to your repository. If you have already committed files to your repository, you will need to remove them from the repository and re-add them after setting up Git LFS.

It is possible to use git lfs migrate to convert existing files in your repository, but this is more in-depth and requires a good understanding of Git.

A common approach is setting up a new repository with Git LFS (and a proper .gitattributes), then copying the files from the old repository to the new one. This way, you can ensure that all files are tracked by LFS from the start.

To use Git LFS with Godot, you need to install the Git LFS extension and configure it to track the file types you want to manage. You can do this by running the following command in your terminal:

git lfs install

This will create a .gitattributes file in your repository that tells Git to use LFS for the specified file types. You can add more file types by modifying the .gitattributes file. For example, to track all GLB files, you can do this by running the following command in your terminal:

git lfs track "*.glb"

When you add or modify files that are tracked by LFS, Git will automatically store them in LFS instead of the regular Git history. You can push and pull LFS files just like regular Git files, but keep in mind that LFS files are stored separately from the rest of your Git history. This means that you may need to install Git LFS on any machine that you clone the repository to in order to access the LFS files.

Below is an example .gitattributes file that you can use as a starting point for Git LFS. These file types were chosen because they are commonly used, but you can modify the list to include any binary types you may have in your project.

# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

# Git LFS Tracking (Assets)

# 3D Models
*.fbx filter=lfs diff=lfs merge=lfs -text
*.gltf filter=lfs diff=lfs merge=lfs -text
*.glb filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text

# Images
*.png filter=lfs diff=lfs merge=lfs -text
*.svg filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.webp filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.hdr filter=lfs diff=lfs merge=lfs -text
*.dds filter=lfs diff=lfs merge=lfs -text

# Audio
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text

# Font & Icon
*.ttf filter=lfs diff=lfs merge=lfs -text
*.otf filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text

# Godot LFS Specific
*.scn filter=lfs diff=lfs merge=lfs -text
*.res filter=lfs diff=lfs merge=lfs -text
*.material filter=lfs diff=lfs merge=lfs -text
*.anim filter=lfs diff=lfs merge=lfs -text
*.mesh filter=lfs diff=lfs merge=lfs -text
*.lmbake filter=lfs diff=lfs merge=lfs -text

For more information on Git LFS, check the official documentation: https://git-lfs.github.com/ and https://docs.github.com/en/repositories/working-with-files/managing-large-files.