跨平台 git 配置的最佳实践?

发布于 2024-08-23 02:16:10 字数 417 浏览 3 评论 0原文

我的许多应用程序用户配置文件都保存在 git 存储库中,以便在多台机器和多个平台之间轻松共享 这些配置文件中有 .gitconfig,其中包含以下用于处理回车换行字符的设置。

[core]
    autocrlf = true
    safecrlf = false

问题

这些设置也适用于 GNU/Linux 平台,这会导致模糊错误。

问题

处理配置文件中这些平台特定差异的最佳实践有哪些?

建议的解决方案

我意识到这个问题可以通过为每个平台建立一个分支并将通用内容保留在 master 中并在 master 向前移动时与平台分支合并来解决。我想知道这个问题是否有任何更简单的解决方案?

Context

A number of my application user configuration files are kept in a git repository for easy sharing across multiple machines and multiple platforms. Amongst these configuration files is .gitconfig which contains the following settings for handling the carriage return linefeed characters

[core]
    autocrlf = true
    safecrlf = false

Problem

These settings also gets applied on a GNU/Linux platform which causes obscure errors.

Question

What are some best practices for handling these platform specific differences in configuration files?

Proposed solution

I realize this problem could be solved by having a branch for each platform and keeping the common stuff in master and merging with the platform branch when master moves forward. I'm wondering if there are any easier solutions to this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的往事 2024-08-30 02:16:10

永远不要打开autocrlf,它只会带来头痛和悲伤。

没有理由在 Windows 上使用 \r\n,所有像样的编辑器(根据定义)都可以处理 \n

Never turn autocrlf on, it causes nothing but headaches and sorrows.

There's no excuse to use \r\n on windows, all decent editors (by definition) can handle \n.

戏舞 2024-08-30 02:16:10

我已经在问题中广泛审查了这种配置设置(crlf):
使用代码分发 git 配置

结论是:

*.java +crlf
*.txt +crlf
...

现在,关于每平台设置的具体问题,分支并不总是正确的工具,特别是对于非程序相关的数据(即,这些设置与您正在开发的内容无关,仅与您正在开发的内容相关) VCS 存储您的开发历史)

如问题 Git:如何维护一个项目的两个分支并仅合并共享数据?:

如果您将系统相关的代码放在不同的目录中并处理构建系统(Makefile 或您使用的任何文件)中的跨平台依赖项,您的生活将会变得更加简单。

在这种情况下,虽然分支可以用于系统相关的代码,但我建议使用支持工具系统相关设置的目录,并使用能够构建适当的 .gitattributes 文件来应用正确设置的脚本取决于存储库部署平台。

I have reviewed that kind of config setting (crlf) extensively in the question:
distributing git configuration with the code.

The conclusion was:

*.java +crlf
*.txt +crlf
...
  • avoid doing any kind of conversion of type of files which don't need it, because of the various side-effect of such a conversion on merges, git status, shell environment and svn import (see "distributing git configuration with the code" for links and references).
  • avoid any crlf conversion altogether if you can.

Now, regarding the specific issue of per-platform settings, branch is not always the right tool, especially for non-program related data (i.e; those settings are not related to what you are developing, only to the VCS storing the history of your development)

As stated in the question Git: How to maintain two branches of a project and merge only shared data?:

your life will be vastly simpler if you put the system-dependent code in different directories and deal with the cross-platform dependencies in the build system (Makefiles or whatever you use).

In this case, while branches could be use for system-dependent code, I would recommend directory for support tools system-dependent settings, with a script able to build the appropriate .gitattributes file to apply the right setting depending on the repo deployment platform.

傲鸠 2024-08-30 02:16:10

我认为你应该让 .gitconfig 取决于用户使用的操作系统。 Windows 用户根本不需要 autocrlf,而 Linux 用户则需要。例如,使用 crlf 保存文本文件,并让 Git 自动为 Linux 用户来回转换文件。

您可能还想检查 .gitattributes ,它允许您定义哪些文件被转换,哪些不被转换。如果配置文件仅位于一个位置,为了安全起见,您可以定义仅在该目录中完成转换。

I think you should have the .gitconfig depend on the operating system the user is using. Windows users don't need autocrlf at all while Linux users do. E.g. save the text files with crlf and have Git convert the files automatically back and forth for the Linux users.

You might also want to check .gitattributes, which allows you to define which files are converted and which are not. If you have the configuration files in just one place, you could define that the conversion is only done in that directory just to be on the safe side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文