My git tips...
Ok, so a handy meme is loose: Handy Git tips. We even had a crazy anatidae requesting us to post this to the Git wiki whatever we send on this regard to our personal blogs.
Following Damog’s post, I will also put my .bashrc snippet:
parse_git_branch() {
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! -z "$branch" ]
then
if ! git status|grep 'nothing to commit .working directory clean' 2>&1 > /dev/null
then
branch="${branch}*"
mod=`git ls-files -m --exclude-standard|wc -l`
new=`git ls-files -o --exclude-standard|wc -l`
del=`git ls-files -d --exclude-standard|wc -l`
if [ $mod != 0 ]; then branch="${branch}${mod}M"; fi
if [ $new != 0 ]; then branch="${branch}${new}N"; fi
if [ $del != 0 ]; then branch="${branch}${del}D"; fi
fi
fi
echo $branch
}
This gives me the following information on my shell prompt:
- The git branch where we are standing
- If it has any uncommitted changes, a * is displayed next to it
- If there are changes not checked in to the index, M (modified), N (new) or D (deleted) is displayed, together with the number of files in said condition. i.e.,
Sometimes, entering a very large git tree takes a second or two... But once it has run once, it goes on quite smoothly.
Of course, I still have this also in .bashrc - but its funcionality pales in comparison:
get_svn_revision() { if [ -d .svn ] then svn info | grep ^Revision | cut -f 2 -d ' ' fi }
I am sure it can be expanded, of course - but why? :) ### Attachments [gitprompt.png](/files/gitprompt.png) (5 KB) ### Comments [alexandrul](http://asimilatorul.com/adapter/category/git/) 2009-09-22 04:35:20 **I've added a line to** I've added a line to substract the number of deleted files from the modified ones:del=`git ls-files -d --exclude-standard|wc -l` let "mod = ${mod} - ${del}" if [ $mod != 0 ]; then branch="${branch}${mod}M"; fi
----- [gwolf]() 2009-09-22 06:18:27 **Thanks, that adds some consistency** Although a removal _is_ a modification, the resulting behaviour is closer to reality :) Thanks! ----- [gwolf]() 2009-09-22 06:23:17 **It is easier if you reorder the lines** I have reordered the snippet incorporating your idea:branch="${branch}*" new=`git ls-files -o $git_opts|wc -l` del=`git ls-files -d $git_opts|wc -l` mod=$(( `git ls-files -m $git_opts|wc -l` - $del )) if [ $mod != 0 ]; then branch="${branch}${mod}M"; fi if [ $new != 0 ]; then branch="${branch}${new}N"; fi if [ $del != 0 ]; then branch="${branch}${del}D"; fi
Heh, it's incredible how you get so used to something you don't notice how it breaks reality ;-) Thanks!