- To visit the state of a repository under certain commit, first clone the repo without checkout:
git clone https://github.com/karpathy/build-nanogpt.git --no-checkoutThis command downloads all the repository data, but does not check out the working files.
- Navigate to the directoryone should see an seemingly empty directory.
cd build-nanogpt- Checkout with a specific commit hash:
git checkout <commit-hash>Tip
This command updates your working directory to match the state of the repository at the specified commit. Keep in mind that when you check out a commit directly, you might enter a "detached HEAD" state, meaning you are not on a branch. To return to a branch, you can use:
git checkout <branch-name>This will point your working directory to the latest commit on that branch.
How do I obtain the full commit hash?
If you have the partial commit hash such as 28916d9, use command git show 28916d9 to display the full commit hash along with the commit's details, such as the author, date, and the changes made.
Finally, command git rev-parse 28916d9 will give the full hash.
You can use this one-line command:
git checkout $(git rev-parse 28916d9)