解决 WSL下的 git 代理 问题
首先,WSL的本身就是虚拟机,自己有着自己的网络协议栈,如果硬要实现直接被实体机直接代理就麻烦许多,所以我只是通过实体机的局域网IP来局域网代理 a
git config --global http.proxy http://*.*.*.*:10808
git config --global https.proxy http://*.*.*.*:10808
还有的 ssh 能用http代理,通过 connect-proxy
apt install -y connect-proxy
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile path/to/ssh_private_key
ProxyCommand connect-proxy -H <Porxy IP>:<port> %h %p
解决 PowerShell 启动加载速度慢
使得 PowerShell 启动加速 1418ms 到秒开
问题: Loading personal and system profiles took 1418ms。D:\UserName\Documents\PowerShell\profile.ps1 里 Conda 初始化每次启动调用 conda.exe,加上 Windows Defender 扫描。
解决:
删掉 D:\UserName\Documents\PowerShell\profile.ps1 里的 conda initialize 代码块(#region 到 #endregion 共5行)
Add-MpPreference -ExclusionProcess “pwsh.exe” Add-MpPreference -ExclusionPath “D:\Software\PowerShell\7” Add-MpPreference -ExclusionPath “D:\UserName\Documents\PowerShell”
[System.Environment]::SetEnvironmentVariable(‘POWERSHELL_UPDATECHECK’, ‘Off’, ‘User’)
cn 函数还在 Microsoft.PowerShell_profile.ps1 里,输入 cn 激活 Conda。
最终配置
# 1. 强力禁止 PowerShell 启动时联网检查更新(节省几百毫秒)
$env:POWERSHELL_UPDATECHECK = 'Off'
# 2. 定义 Conda 按需加载函数
# 以后想用 Conda 时,在终端输入 cn 即可,平时不加载,保证秒开
function cn {
$Env:CONDA_EXE = "path/to/Anaconda3\Scripts\conda.exe"
$Env:_CE_M = ""
$Env:_CE_CONDA = ""
$Env:_CONDA_ROOT = "path/to/Anaconda3"
$Env:_CONDA_EXE = "path/to/Anaconda3/Scripts/conda.exe"
$CondaModuleArgs = @{ChangePs1 = $True}
# 只有执行 cn 命令时才会导入这个沉重的模块
Import-Module "$Env:_CONDA_ROOT\shell\condabin\Conda.psm1" -ArgumentList $CondaModuleArgs
Remove-Variable CondaModuleArgs
Write-Host "--- Conda 环境已激活 ---" -ForegroundColor Green
}
Linux 与 Windows 换行符导致的 git 提示文件修改
创建 .gitattributes
* text=auto
*.cpp text eol=lf
*.h text eol=lf
*.c text eol=lf
*.hpp text eol=lf
*.txt text eol=lf
*.md text eol=lf
*.json text eol=lf
*.xml text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.sh text eol=lf
Makefile text eol=lf
*.sln text eol=crlf
*.vcxproj text eol=crlf
*.vcxproj.filters text eol=crlf
*.vcxproj.user text eol=crlf
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.exe binary
*.dll binary
*.lib binary
git add --renormalize .
git commit -m "build: force all text files to LF for cross-platform consistency"