共享 Git 存储库中的 .editorconfig [英] .editorconfig in shared Git repository

查看:29
本文介绍了共享 Git 存储库中的 .editorconfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已准备好要在多个 Git 存储库上使用的 .editorconfig 文件.每个存储库都包含一个 Visual Studio 解决方案 (C#).我的第一个想法是将 .editorconfig 文件放在自己的存储库中,然后将其作为子模块包含在所有解决方案存储库"中.然而问题是:子模块将位于子文件夹中.因此,包含的 .editorconfig 将不会应用于整个项目/解决方案(而只会应用于子文件夹及其子文件夹).在我看来,我也无法在解决方案配置文件 (.sln) 中指定解决方案范围内 .editorconfig 的路径.

I have prepared my .editorconfig file which I want to use on multiple Git repositories. Each repository holds a Visual Studio solution (C#). My first thought was to put the .editorconfig file in its own repository and then include it in all "solution repositories" as submodule. The problem however: The submodule will be in a subfolder. The contained .editorconfig will thus not be applied to the whole project/solution (but only to the subfolder and its children). It seems to me that I cannot specify a path to my solution-wide .editorconfig in the solution configuration file (.sln), either.

在多个 Git 存储库之间实际共享单个 .editorconfig 文件的最佳方法是什么?.editorconfig 文件仍然需要进行版本控制(因此在用户之间共享),即.没有本地 editorconfig 配置.

What is the best approach to actually share a single .editorconfig file between multiple Git repositories? The .editorconfig file still needs to be version controlled (and thus shared between users), ie. no local editorconfig configuration.

推荐答案

我自己找到了一个解决方案,使用共享存储库作为我想要的子模块:这是一个符号链接!

I found a solution myself using a shared repository as submodule as I wanted: It's a symbolic link!

例如,如果您的子模块名为 Global,请进入解决方案的根目录并通过以下方式创建指向子文件夹 Global 中实际文件的符号链接:>

For example, if your submodule is called Global, go into the root of your solution and create a symbolic link to the real file in subfolder Global via:

mklink .editorconfig .\Global\.editorconfig

这个链接可以像任何其他文件一样提交和推送.Gitea(我用作服务器)甚至显示一个小箭头作为文件符号的叠加.显然它知道它只是一个符号链接.当我在 Windows 机器上克隆这个存储库时,符号链接按预期工作.也许它甚至适用于 *nix 系统;不过我没试过.

This link can be committed and pushed like any other file. Gitea (which I am using as server) even shows a small arrow as overlay for the file symbol. Apparantly it knows that it is just a symbolic link. When I clone this repository on a Windows machine, the symbolic link works as expected. Maybe it even works on *nix systems; I did not try though.

我拒绝使用此解决方案:VS2017 (15.8.2) 不会立即获取更改.必须关闭并重新打开解决方案.如果您使用的是真正的 .editorconfig 文件更改,则会立即检测到自 15.8 Preview 3 起.

I draw back of this solution: VS2017 (15.8.2) does not pick up changes immediately. One has to close and re-open the solution. If you are using a real .editorconfig file changes are detected immediately since 15.8 Preview 3.

我们决定不将符号链接提交到 Git,因为它曾经被 Gitea 搞砸了(可能是一个错误),并且因为我们有非 Windows 开发系统.相反,我们有一个后克隆脚本"与我们项目文件中的条件错误相结合 <Error Condition="!Exists('$(SolutionDir).editorconfig')" Text=".editorconfig is missing. Please首先运行 $(SolutionDir)_post_clone_script.bat."/>.

We decided not to commit the symbolic link to Git because it once screwed by Gitea (might have been a bug) and because we have non-Windows development systems. Instead we have a 'post clone script' in combination with a conditional error in our project files <Error Condition="!Exists('$(SolutionDir).editorconfig')" Text=".editorconfig is missing. Please run $(SolutionDir)_post_clone_script.bat first." />.

这篇关于共享 Git 存储库中的 .editorconfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆