Git高速下載
程序員面試資料大全|各種技術書籍等資料-1000G
一、安裝前準備:避免環境沖突
1. 檢查系統殘留(Windows)
# 檢查舊版Git殘留
where git
where git.exe# 檢查環境變量
$env:PATH -split ';' | Select-String 'git'# 清理殘留(管理員權限)
Uninstall-Module -Name Git -AllVersions -Force
Remove-Item -Path "C:\Program Files\Git" -Recurse -Force
2. 驗證系統兼容性
系統版本 | 支持情況 | 注意事項 |
---|---|---|
Windows 7 | ?? 僅Git 2.34以下 | 需安裝KB4490628補丁 |
macOS 10.13- | ?? 需升級命令行工具 | 安裝Xcode Command Line Tools |
Ubuntu 16.04 | ?? 需PPA源 | 使用git-core PPA |
CentOS 7 | ?? 版本較舊 | 需IUS倉庫升級 |
3. 權限準備
# Linux/macOS 確保有sudo權限
id -u # 返回0表示root# Windows 關閉殺毒軟件實時防護
Set-MpPreference -DisableRealtimeMonitoring $true
二、Windows安裝避坑指南
1. 安裝包選擇
- 官方推薦:Git for Windows
- 版本陷阱:
- 32位系統選
Git-2.xx.x-32-bit.exe
- ARM設備選
Git-2.xx.x-arm64.exe
- 32位系統選
2. 安裝步驟關鍵配置
避坑配置詳解:
-
組件選擇(必須勾選):
- Git Bash Here
- Git GUI Here
- Associate .git* files
- Check daily for updates (避免自動升級沖突)
-
環境變量配置:
- 選 “Git from the command line and also from 3rd-party software”
- 避免選"Use Git from Git Bash only"
-
行尾轉換:
- 選 “Checkout as-is, commit as-is”
- 避免Windows/Unix換行符混用問題
-
終端模擬器:
- 選 “Use Windows’ default console window”
- 避免MinTTY兼容性問題
3. 安裝后驗證
# 驗證安裝
git --version# 檢查關鍵配置
git config --global -l | Select-String core.autocrlf# 正確應顯示
core.autocrlf=false
4. 常見問題解決
問題:git
命令無法識別
? 解決方案:
- 重啟所有終端
- 檢查環境變量:
echo %PATH%
- 手動添加路徑:
C:\Program Files\Git\cmd
問題:SSH認證失敗
? 解決方案:
# 重新生成密鑰
ssh-keygen -t ed25519 -C "your_email@example.com"# 添加密鑰到agent
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519
三、macOS安裝避坑指南
1. 安裝方式對比
2. Homebrew安裝(推薦)
3. 官方安裝包問題解決
4. 常見問題
問題:xcrun: error: invalid active developer path
? 解決方案:
xcode-select --install
sudo xcode-select --switch /Library/Developer/CommandLineTools
問題:brew install 卡在Cloning…
? 解決方案:
四、Linux安裝避坑指南
1. 各發行版安裝命令
2. 權限問題解決
3. 配置優化
# 提高大倉庫性能
git config --global core.preloadIndex true
git config --global core.fscache true
git config --global pack.threads 8# 設置默認編輯器(避免vim陷阱)
git config --global core.editor "code --wait"
程序員面試資料大全|各種技術書籍等資料-1000G
Git高速下載