Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

I'm looking for a Git alternative to "svn info".

Today I added some information that Subversion gives me with the "svn info" command right into my build, and that is then pushed into a source file that prints this during startup. That way I always know where that build came from and how to get it back again.

If you have "svn info" like URL, Repository Root, Repository UUID and the Revision, you have a good link between what is deployed and the buildsystem. And if someone reports a bug you know where that software came from, and since that information was automatically included, the risk of human error is smaller.

Now the question is, what information do I need to get from Git so I can later identify where that build came from? And how do I use that information to switch back to exactly that version?

(Maybe I need to add some information about the "build computer" as well since Git is distributed.)

Update: Using rev-parse was really useful, and I got something like this:

[email protected]:~/git_test$ git rev-parse HEAD


And with that magic number it is later possible to do:

[email protected]:~/git_test$ git checkout 72ce5f3e13c61f76fde5c58cefc85eed91b6f1f8

And I am back where I was.

Update: I think that if I take some parts from that scripts VonC provided and put them into my buildfile I will get the result I was looking for.


A note on "git describe". You need a real tag (tag -a) earlier in you branch history to make this work or you will get something like this.

fatal: cannot describe '72ce5f3e13c61f76fde5c58cefc85eed91b6f1f8'

The problem is also described in Git Tag Does the Wrong Thing by Default.

But please note that a checkout seems to work anyway, even though that was an error message.

git checkout 72ce5f3e13c61f76fde5c58cefc85eed91b6f1f8

The normal thing though seems to be that you create something like a "ver1.0" tag, and then if you continue to work you get something like this:

[email protected]:~/git_test$ git describe 


[email protected]:~/git_test$ git tag -a ver2.0

[email protected]:~/git_test$ git describe 


[email protected]:~/git_test$ git commit . -m "something..."

Created commit ac38a9d: something...

 1 files changed, 1 insertions(+), 0 deletions(-)

[email protected]:~/git_test$ git describe 


So when you use describe correctly it does work and may produce a more human-readable results, and it can be really useful as well.

1 Answer

0 votes
by (62.9k points)

For someone who is looking for remote and branch information.

git remote show origin

can make a script displaying "sn info"

# date: 2008 Jun 12

# license: MIT


# Based on discussion at

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 "== Local Branches:"

git branch


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

cat .git/config


echo "== Most Recent Commit"

git log --max-count=1


echo "Please type the command 'git log' for viewing additional commits, or 'git show' for viewing each commit information."


echo "Not a git repository."


popd >/dev/null


Which would produce something like:

== Remote URL: origin [email protected]:pk/my-project.git

== Remote Branches:



[email protected]

[email protected]

[email protected]

== Local Branches:


* work

== Configuration (.git/config)


repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

[svn-remote "svn"]

url = svn+ssh://

fetch = my-project/trunk:refs/remotes/trunk

[remote "origin"]

url = [email protected]:pk/my-project.git

fetch = refs/heads/*:refs/remotes/origin/*


user = pk

repo = my-project

== Most Recent Commit

commit b47dce8b4102faf1cedc8aa3554cb58d76e0cbc1

Author: Prabhpreet Kaur

Date: Wed Jun 11 17:00:33 2008 -0600


Added changes to database schema that may permit decentralization from content pointers table

type 'git log' for additional, or 'git show' for full commit details.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories