How to checkout a specific version of git repository

A public git repository is often shared by multiple developers who constantly contribute new code and fixes, and users who check out code to try it. Along with code itself, a git repository contains full commit history of the code, as well as revision tracking information. As such, you can easily checkout a particular version of specific files from git repository if you want. In order to checkout a specific version of git repository, see the following examples.

I assume that you have already cloned a git repository as follows.

$ git clone
$ cd

Before checking out a specific version, you probably want to examine the change history first.

To view the commit history of the current directory:

$ git log

To view the commit history of a specific file:

$ git log -p <filename>

The sample commit history looks as follows.

commit 7a51831cb4dc6b2ae56ad24400ba1fdfed064528
Merge: 69f8529 6fd2611
Author: Peter 
Date:   Wed Nov 14 21:58:47 2012 +0000

    Merge "Fixed a critical bug"

The history shows you, for each commit entry, detailed information about the commit, as well as 40-character checksum hash (e.g., 7a518xxxxxx). The checksum hash is essentially a version number you need to remember in order to checkout next.

To checkout a specific version of the current directory:

$ git checkout <checksum_hash>

To checkout a specific version of a file:

$ git checkout <checksum_hash> <file>

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

One thought on “How to checkout a specific version of git repository

  1. Thanks, but this does not work for the repository I'm using, which is raspberrypi/linux. I cloned it first today and the ONLY commit I can see with "git log" is the very last one, when this branch was merged with another. BUT, on, I can see a long list of commits, all sadly unavailable to me. Any idea why this might be?

Leave a comment

Your email address will not be published. Required fields are marked *