为 git 实现 'svn info' 的功能

git没有类似svn中的’svn info’功能, 自己写一个脚本来实现这样的功能:

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
#!/bin/sh

# 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 --no-pager 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

运行效果如下:

== Remote URL: origin https://danshan@bitbucket.org/danshan/haidaofm.git (fetch)
origin https://danshan@bitbucket.org/danshan/haidaofm.git (push)
== Remote Branches:
origin/HEAD -> origin/master
origin/master

== Local Branches:
* master

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

== Most Recent Commit
commit 843423895f429aa6d78be1b2d26fb93472c64548
Author: Dan Shan
Date: Mon Oct 15 07:12:33 2012 +0400

webapi
[bugfix]
1. fix some import error of java

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

Codes Here: https://gist.github.com/danshan/2e631fb9e7caff2d5a3880373086f7d2