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.
Before checking out a specific version, you probably want to examine the change history first.
To view the commit history of the current directory:
To view the commit history of a specific file:
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:
To checkout a specific version of a 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.