Getting git revision by specific date

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

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


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

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`"



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.


Leave a Reply

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

You are commenting using your 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