很多有用的 git 技巧

2010-10-04 17:38:33 +08:00
 Livid
http://stackoverflow.com/questions/347901/what-are-your-favorite-git-features-or-tricks
4949 次点击
所在节点    git
5 条回复
eth2net
2010-10-04 17:58:20 +08:00
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
哇,前两天的问题终于解决了。
kidblg
2010-10-04 21:31:53 +08:00
准备转git
lepture
2010-10-04 23:52:52 +08:00
@eth2net 找了好一会儿了, zsh 该怎么处理呢? 试了几个,都不成功~~
harryxu
2010-10-05 02:01:06 +08:00
raecoo
2010-10-05 17:30:51 +08:00
parse_git_branch() {
RSLT=''
GIT_BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* //'`
if [ "$GIT_BRANCH" ]
then
GIT_STATUS=`git status 2> /dev/null | grep 'working directory clean'`
CLR='2'
if [ "$GIT_STATUS" ]
then
CLR='2'
else
CLR='1'
fi
RSLT="[3${CLR};40m(${GIT_BRANCH})[0m"
fi
echo $RSLT
}

parse_git_remote_status() {
RSLT=''
GIT_REMOTE_STATUS=`git status 2>/dev/null | grep 'Your branch is ahead of'`
if [ "$GIT_REMOTE_STATUS" ]
then
RSLT="[31;40mr[0m"
fi
echo $RSLT
}

COL=`expr $COLUMNS - 1`
LINE=''
COUNT=0
while test ${COL} -gt $COUNT
do
let COUNT++
LINE="${LINE}-"
done

export PS1='[0;36m[${COL}D[0;33m[\u:[0;35m\W[0;33m][0;36m$(parse_git_branch)[0;32m
\$ '

[raecoo:edm](master) 三段分别用不同的颜色显示

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/3090

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX