gpt4 book ai didi

visual-studio - GitHub 打破了 Visual Studio 的缩进

转载 作者:行者123 更新时间:2023-12-04 01:59:35 25 4
gpt4 key购买 nike

我想知道为什么我的代码在将其推送到 GitHub 后变得困惑。
例如,当我缩进某个类的成员时,它们都对齐了,它在 Visual Studio 中看起来不错,在 GitHub 中看起来很丑陋。

下面是一个例子:

Indentation in Visual Studio

以及它在 GitHub 中的样子:

Indentation in GitHub

最佳答案

首先,确保所有缩进都是实际的制表符,而不是空格。

其次,默认情况下,GitHub 会将标签显示为 8 个字符。
因此,尝试查看相同的 GitHub 页面,但在其 URL 末尾添加:?ts=4
那是:

https://gist.github.com/razzorflame/ef776ddef260608bc1a8799090af629e?ts=4

tabs looks good

或者... configure your Visual Studio to use a tab width of 8 (虽然不理想)。

mentioned here ,您可以添加 .editorconfig (如 this one 的要点):

root = true

[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
[*.{js,jsx,html,sass}]
charset = utf-8
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

然后 GitHub 应该使用正确的宽度显示标签 (4)。

作为 .editorconfig的使用说明,Git 本身以及 Git 2.26(2020 年第一季度)告诉 .editorconfig在这个项目中, *.txt文件用制表符缩进。

commit 7047f75 (05 Jan 2020) by Hans Jerry Illikainen ( illikainen ) .
(由 Junio C Hamano -- gitster -- 合并于 commit 34246a1 ,2020 年 1 月 30 日)

editorconfig: indent text files with tabs

Signed-off-by: Hans Jerry Illikainen

Previously, the .editorconfig did not specify an indentation style for text files.

However, a quick look for indentation-like spacing suggest that tabs are more common for documentation:

$ git grep -Pe '^ {4}' -- '*.txt' |wc -l 
2683
$ git grep -Pe '^\t' -- '*.txt' |wc -l
14011

Note that there are a lot of files that indent list continuations (and other things) with a single space -- if the first search was made without the fixed quantifier the result would look very different.
However, the result does correspond with my anecdotal experience when editing Git documentation.

This commit adds *.txt to .editorconfig as an extension that should be indented with tabs.

关于visual-studio - GitHub 打破了 Visual Studio 的缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com