Getting git revision by specific date

Few time ago (years) I explained how to get a specific subversion revision by date (portuguese article):

https://acassis.wordpress.com/2007/09/08/baixando-fonte-de-repositrio-subversion-por-data

Today I faced the same situation but using git. Bad news: git doesn’t have –revision tag. Fortunately I found a way to do same thing.
You can use this:

$ git rev-list yourbranch -n 1 --first-parent --before=YYYY-MM-DD

I.e.:

$ git rev-list master -n 1 --first-parent --before=2009-05-20
c06326c73bf90e48a8e1cf8893ad31c575423f50

Now just use the returned hash to checkout that revision:

$ git checkout c06326c73bf90e48a8e1cf8893ad31c575423f50

Also you can execute both command using a single line:

git checkout "`git rev-list rev -n 1 --first-parent --before=YYYY-MM-DD`"

Source:
http://kerneltrap.org/index.php?q=mailarchive/git/2008/2/11/817714/thread

Advertisements

2 thoughts on “Getting git revision by specific date

  1. Sorry for the late comment – I’ve just found the article when struggling with identical issue.
    I’d like to point that getting git sources by date is unreliable.
    Git rev-list is used to find last commit before given date. If anyone performs merge on git repository, then git history will be modified. In such case rev-list may return different commit id, effectively pointing to sources not the same as for the first time.
    This is because of distributed git nature.

    I haven’t found that info anywhere, so I’m posting it here. I think it may be useful.

    Regards,
    Robert

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s