#!/bin/bash # 设置错误时立即退出 set -e # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # 日志函数 log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # 安装Git install_git() { log_info "安装Git..." # 安装Git sudo apt-get update sudo apt-get install -y git # 安装Git工具 sudo apt-get install -y git-extras sudo apt-get install -y git-flow sudo apt-get install -y git-lfs log_info "Git安装完成" } # 配置Git configure_git() { log_info "配置Git..." # 配置Git全局设置 git config --global core.autocrlf input git config --global core.fileMode false git config --global core.ignorecase false git config --global core.quotepath false git config --global core.safecrlf warn git config --global core.editor "vim" # 配置Git颜色 git config --global color.ui true git config --global color.branch.current "yellow reverse" git config --global color.branch.local "yellow" git config --global color.branch.remote "green" git config --global color.diff.meta "yellow bold" git config --global color.diff.frag "magenta bold" git config --global color.diff.old "red" git config --global color.diff.new "green" git config --global color.status.added "green" git config --global color.status.changed "yellow" git config --global color.status.untracked "cyan" git config --global color.status.deleted "red" # 配置Git别名 git config --global alias.st "status" git config --global alias.co "checkout" git config --global alias.br "branch" git config --global alias.ci "commit" 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" git config --global alias.lga "log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" git config --global alias.df "diff" git config --global alias.dc "diff --cached" git config --global alias.unstage "reset HEAD --" git config --global alias.last "log -1 HEAD" git config --global alias.visual "!gitk" # 配置Git提交模板 cat > ~/.gitmessage << EOF # (): # # # #