git info

给git增加类似svn info这样的命令
新增一个sh文件,比如说放到~/bin/目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#git-info.sh
#!/bin/bash

# author: Duane Johnson
# email: duane.johnson@gmail.com
# date: 2008 Jun 12
# license: MIT
# 
# Based on discussion at http://kerneltrap.org/mailarchive/git/2007/11/12/406496

pushd . >/dev/null

# Find base of git directory
while [ ! -d .git ] && [ ! `pwd` = "/" ]; do cd ..; done

# Show various information about this git directory
if [ -d .git ]; then
  echo "== Remote URL: `git remote -v`"

  echo "== Remote Branches: "
  git branch -r
  echo

  echo "== Local Branches:"
  git branch
  echo

  echo "== Configuration (.git/config)"
  cat .git/config
  echo

  echo "== Most Recent Commit"
  git log --max-count=1
  echo

  echo "Type 'git log' for more commits, or 'git show' for full commit details."
else
  echo "Not a git repository."
fi

popd >/dev/null

增加可执行权限:


chmod +x git-info.sh

增加别名(我的系统编辑文件~/.bash_profile,增加一行):


alias gi='~/bin/git-info.sh'

到git版本库目录下执行gi:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
HoLin:demo holin$ gi
== Remote URL: origin        git@git.exmample.com:demo.git
== Remote Branches: 
  origin/HEAD
  origin/master

== Local Branches:
* master

== Configuration (.git/config)
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git@git.example.com:demo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

== Most Recent Commit
commit ea37e0362feef0c2fb1234c35f30624246ba1655
Author: HoLin <holin@example.com>
Date:   Tue Jan 20 15:12:37 2009 +0800

    add question parser unit test

Type 'git log' for more commits, or 'git show' for full commit details.

参考


Wiki首页 | 查看所有 | 编辑 | 输出到博客 | 历史版本