Moving from SVN to git: $Id:$ equivalent

In SVN (and CVS), you could include special strings such as


and after a commit, the revision number would appear after “Id:”, which was a convenient way to retrieve the revision for instance in a print statement.

Apparently, with GIT, the equivalent does not exist by default. Indeed somebody could refer to version 1.1 of a file but your
version 1.1 of that file is different and so it would not make sense to keep track of a revision.

Yet, there is way to include the hash from GIT. First, go the repository you are working one and add (if you want to add $Id:$ in a Python code):

cat .git/info/attributes 
# see man gitattributes
*.py ident

Then put $Id$ somewhere in the file (on top generally)

Then commit. Note you will need to delete the file and check it out again:

git commit
git co

You should now see the $Id: followed by a commit hash string:

# $Id: 143e77a7f07343b14 $


Please follow and like us:
This entry was posted in Software development, Uncategorized and tagged . Bookmark the permalink.

One Response to Moving from SVN to git: $Id:$ equivalent

  1. Sander says:

    I have no experience with SVN , butI believe the git way of doing this would be with tags.

    After a specific commit, you can do:
    git tag -a -m “”
    Afterwards, you can simply do:
    git checkout
    That will check you out to the specific commit where the tag was created.

    To push tags:
    git push –tags

    To pull, simply:
    git fetch

Leave a Reply

Your email address will not be published.