终端shell显示当前git分支_修订版

终端shell显示当前git分支

                                                          

修改前:

 

 

修改后:

 

 

项目当前的分支比较多,所以修改时,不太注意的话,分支就容易弄错,基于以上原因,从网上学习找到了一个配置,在当前的命令终端显示当前修改的项目分支。

 

仅供参考。

 

Ubuntu 系统,修改一下文件 (IP地址,按照自己的服务器配置)

\\192.168.3.30\release330\.bashrc

 

.bashrc文件最后 增加获取git当前分支的方法

 

function git_branch {

    ref=$(git symbolic-ref HEAD 2> /dev/null) || return;

    echo "("${ref#refs/heads/}") ";

}

 

修改下面内容

 

if [ "$color_prompt" = yes ]; then

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

else

修改后

PS1="${debian_chroot:+($debian_chroot)}\[\e[m\]\u@\h\[\033[00m\]:\[\e[m\]\w\[\033[0m\] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\$ "

修改前

#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

fi

posted @ 2014-07-04 10:28  xiaoaidelala  阅读(523)  评论(0编辑  收藏  举报