Git官网(https://git-scm.com/)
淘宝镜像网站(https://npm.taobao.org/mirrors/git-for-windows/)
下载源码包
https://mirrors.edge.kernel.org/pub/software/scm/git/
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.27.0.tar.gz
编译安装,此处演示2.27.0版本。
tar xf git-2.27.0.tar.gz
cd git-2.27.0
yum install -y gcc curl-devel openssl-devel zlib-devel
yum install expat-devel gettext-devel # 这两个应该没有必要安装,没发现影响什么功能,且会依赖安装git命令,所以最后需要卸载git,使用我们编译的即可
./configure --prefix=/usr/local/git
make -j$(nproc) && make install
Git 命令补全设置
cd ./contrib/completion cp git-completion.bash git-prompt.sh /etc/profile.d/ cd /etc/profile.d/ && ln -s git-completion.bash git-completion.sh
cat << 'EOF' > /etc/profile.d/git.sh export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM="verbose git svn" export GIT_HOME=/usr/local/git export PATH=$PATH:$GIT_HOME/bin EOF
定制git命令提示符
cat << 'EOF' >> /etc/bashrc export PS1='[e[1;32m][u@h W [ 33[1;31m]$(__git_ps1 "(%s)")[e[1;32m]]$ [e[0m]' EOF
也可以这样子PS1='$(__git_ps1 "(%s)")'$PS1,提示符绿色是xshell的功能,如下,最好自定义的这些参数都写在if里面,避免非登陆时的bash中变量多次叠加。
if shopt -q login_shell ; then # export TIME_STYLE='+%Y-%m-%d %H:%M:%S' # export PS1='[e[1;32m][u@h W [ 33[1;31m]$(__git_ps1 "(%s)")[e[1;32m]]$ [e[0m]' # export PS1='$(__git_ps1 "(%s)")[u@h W]$ ' export PS1='$(__git_ps1 "(%s)")'$PS1 fi
*************************************************************************************************************
如下,直接追加在bashrc中,导致PS1变量多次叠加。
写在if里面,显示效果正常。
效果如下