feat(git-config): 新增推荐 .gitattributes(换行符/编码属性模板)
从文档站《Git for Windows》笔记的代码块提取,供直接下载/引用。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
42f6886b88
commit
71cf9e8cc2
3 changed files with 95 additions and 0 deletions
|
|
@ -7,3 +7,8 @@
|
|||
- [install-my-git-bash](my-git-bash/SKILL.md) — 在 Windows Git Bash 上安装 xnng/my-git-bash 终端美化与工具集(mintty 主题 / git 提示符 / tmux / tree / Powerline 字体 / alias),按用户偏好安全增量安装。
|
||||
|
||||
- [install-wsl2-ubuntu](wsl2-ubuntu/SKILL.md) — 在 Windows 11 上启用 WSL2 并安装 Ubuntu 22.04(国内网络实测路径:DISM 启用功能 + GitHub MSI 经 ghfast 镜像装运行时 + 清华镜像下 rootfs + wsl --import;附 NDK r16b 交叉编译环境)。
|
||||
|
||||
## 配置模板
|
||||
|
||||
- [git-config](git-config/) — 跨平台 Git 配置模板,含推荐的 `.gitattributes`(换行符 / 编码属性 + 匹配优先级注释)。
|
||||
|
||||
|
|
|
|||
78
git-config/.gitattributes
vendored
Normal file
78
git-config/.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# https://git-scm.com/docs/gitattributes
|
||||
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
|
||||
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-config.html
|
||||
|
||||
|
||||
# 回车换行默认值声明 ---------------------------------------------------------------------------------
|
||||
# 名词说明 check in: 对应 commit, check out: 对应 cherry-pick, pull 等
|
||||
|
||||
# 笔记中回车换行的基本原则:(下文 core.xxx 可以认为是 .gitatrributes 中未显示指定时,使用的默认回车换行类型)
|
||||
# checkout 时,回车换行不变: git config core.autocrlf false
|
||||
# false: If you're a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false
|
||||
# true: If you're on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code, and convert CRLF endings into LF when you check in code.
|
||||
# input: If you're on a Linux or macOS system that uses LF line endings, You can tell Git to convert CRLF to LF on commit and convert CRLF to LF on pull, by setting core.autocrlf to input.
|
||||
# 对于跨平台发开同,同时不同平台只能以不同的后缀编译代码时,windows 平台设置 true,linux 平台设置 input。需要注意的是,由于 Linux 用户通常不会遇到 CRLF 换行符,因此 input 设置主要是为了防止从其他平台(如 Windows)检入的代码中出现换行符问题。
|
||||
# commit 时,
|
||||
|
||||
# core.eol: 仅在 core.autocrlf false 生效。 笔记默认让有 text 属性(包括 git 自动判断有 text 属性)的回车换行使用 core.eol 设置值。
|
||||
# Sets the line ending type to use in the working directory for files that have the text property set when core.autocrlf is false. Alternatives are lf, crlf and native, which uses the platform's native line ending. The default value is native. See gitattributes[5] for more information on end-of-line conversion.
|
||||
|
||||
# .gitattributes 匹配优先级 -------------------------------------------------------------------------
|
||||
# 1、Git 仓库的 .git/info/ 目录下,其内的属性设置具有最高的优先级,会覆盖其他位置的相同属性设置。
|
||||
# 2、离文件越近的 .gitattributes 文件中的规则优先级越高。然后再是由 Git 配置变量 core.attributesFile 指定的文件。之后再是 系统范围属性文件:通常位于 /etc/gitattributes。
|
||||
# 3、在同一个 .gitattributes 文件中,后面的规则会覆盖前面的规则。
|
||||
|
||||
# 属性说明 ------------------------------------------------------------------------------------------
|
||||
|
||||
# text:
|
||||
# 1. set:
|
||||
# a. When a matching file is added to the index, the file's line endings are normalized to LF in the index every time the file is checked in, even if the file was previously added to Git with CRLF line endings.
|
||||
# b. When the file is copied from the index to the working directory, its line endings may be converted from LF to CRLF depending on the eol attribute, the Git config, and the platform (see explanation of eol below).
|
||||
# 2. Unset, e.i. `-text`. Unsetting the text attribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout.
|
||||
# 3. `text=auto`: When text is set to "auto", Git decides by itself whether the file is text or binary.
|
||||
# 4. `Unspecified`: If the text attribute is unspecified, Git uses the core.autocrlf configuration variable to determine if the file should be converted.
|
||||
#
|
||||
# elf:
|
||||
# 1、 Unspecified:
|
||||
#
|
||||
# c、 If text is set but neither of those variables is, the default is eol=crlf on Windows and eol=lf on all other platforms.
|
||||
|
||||
# 具体属性如下 --------------------------------------------------------------------------------------
|
||||
* -text
|
||||
|
||||
*.txt text
|
||||
|
||||
*.vcproj text eol=crlf
|
||||
*.bat text eol=crlf ecoding=gbk
|
||||
*.tat text eol=crlf
|
||||
*.md text eol=crlf
|
||||
*.ps1 text working-tree-encoding=UTF-16LE eol=crlf
|
||||
|
||||
*.sh text eol=lf
|
||||
*.cmake text eol=lf
|
||||
*.cpp text eol=lf
|
||||
*.c text eol=lf
|
||||
*.h text eol=lf
|
||||
*.hpp text eol=lf
|
||||
*.css text eol=lf
|
||||
*.puml text eol=lf
|
||||
*.py text eol=lf
|
||||
*.xml text eol=lf
|
||||
*.yaml text eol=lf
|
||||
|
||||
*.jpg -text
|
||||
*.png -text
|
||||
*.ico -text
|
||||
*.7z -text
|
||||
*.zip -text
|
||||
*.jar -text
|
||||
*.gz -text
|
||||
*.class -text
|
||||
*.eddx -text
|
||||
*.emmx -text
|
||||
*.mp3 -text
|
||||
*.pcm -text
|
||||
*.pdf -text
|
||||
*.so -text
|
||||
*.xlsx -text
|
||||
*.lsx -text
|
||||
12
git-config/README.md
Normal file
12
git-config/README.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# git-config
|
||||
|
||||
跨平台 Git 配置模板。
|
||||
|
||||
## .gitattributes
|
||||
|
||||
推荐的 `.gitattributes` 换行符(EOL)与编码配置示例,含 `text` / `eol` / `working-tree-encoding` 属性说明与匹配优先级注释。
|
||||
|
||||
- 查看:[.gitattributes](.gitattributes)
|
||||
- 原始内容(可直接下载):[raw](/gits/fnzhang/tool-skills/raw/branch/main/git-config/.gitattributes)
|
||||
|
||||
背景说明见文档站笔记《Git for Windows》。
|
||||
Loading…
Add table
Add a link
Reference in a new issue