git 状态提示

1 下载git源码包

在git源码包(https://github.com/git/git.git)的contrib/completion目录下有两个文件

  • git-completion.bash 自动补全脚本
  • git-prompt.sh 状态提示脚本.
$ ls  /etc/profile.d/git-*
/etc/profile.d/git-completion.sh  /etc/profile.d/git-prompt.sh

2 放到/etc/profile.d/目录下,git-completion.bash改名为 git-completion.sh

sudo cp git-completion.bash /etc/profile.d/git-completion.sh
sudo cp git-prompt.sh /etc/profile.d/

3 修改环境变量 /etc/profile

sudo vim /etc/profile
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM="verbose git svn"
PS1='\[\033[1;32m\]\u@\h \[\033[1;34m\]\W\[\033[1;31m\]$(__git_ps1 " (%s)")\[\033[1;35m\] $ \[\033[0m\]'

4 重启查看效果

git 状态提示_第1张图片
image.png

你可能感兴趣的:(git 状态提示)