适用场景:同时使用 Windows 和 Ubuntu 进行开发的 Java 程序员。
解决痛点:换行符冲突 (LF vs CRLF)、中文文件名乱码、Java 长路径报错。
1. 通用配置 (所有系统必输)
无论在 Windows 还是 Linux,请首先执行以下命令打好基础。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
git config --global core.quotepath false
git config --global pull.rebase true
git config --global init.defaultBranch main
git config --global alias.st status git config --global alias.co checkout git config --global alias.ci commit git config --global alias.br branch
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
2. Windows 专属配置
请打开 PowerShell 或 CMD 执行。
1 2 3 4 5 6 7 8 9 10
|
git config --global core.autocrlf true
git config --global core.longpaths true
git config --global core.filemode false
|
3. Linux (Ubuntu) 专属配置
请打开 Terminal 执行。
1 2 3 4 5 6 7 8
|
git config --global core.autocrlf input
git config --global core.protectNTFS true
|