修改 Git 安裝目錄下的 etc/profile 文件(非 profic),末尾添加別名:
alias ls="ls --show-control-chars"
重啟 Git Bash 即可正常顯示中文文件名。
Git 擁有三級配置文件,優先級由高到低:
| 層級 | 命令 | 文件位置 | 作用範圍 |
|---|---|---|---|
| 倉庫級 | git config -e | .git/config | 僅當前倉庫 |
| 全局級 | git config -e --global | ~/.gitconfig (Windows: C:\Users\用戶名\.gitconfig) | 當前用戶所有倉庫 |
| 系統級 | git config -e --system | /etc/gitconfig | 系統所有用戶 |
高優先級配置會覆蓋低優先級,實現靈活的配置繼承。
假設本地項目已就緒,需先在服務器創建同名裸倉庫,再執行:
cd myproject
git init # 本地初始化
git add . # 暫存所有文件
git commit -m 'initial commit' # 本地提交
git remote add origin git@server_ip:/path/to/repo.git # 關聯遠程倉庫
git push origin master # 推送至遠程
關鍵點:遠程倉庫路徑 jewels.git 為服務器端項目名,與本地目錄名無關。建議使用 SSH 協議(git@ip:path)實現免密推拉。
git config --list 查看生效配置user.name 和 user.email 為提交記錄標識身份.gitignore 排除無需版控文件