Reputation: 677
From time to time I want to do this simple thing using Git:
I have a git repository with several commits.
Now how do I checkout all directories and files of a particular commit ?
Should I clone the repo locally and then do a git checkout for that particular commit ?
Is there a simpler command which just checks out all the files and directories of a particular commit to a local directory ? I'm just going to use those files and I'm not going to change them etc, So I do not need to create a local repo just for checking out a few files and viewing them. Correct ?
Upvotes: 3
Views: 2713
Reputation: 4810
I think you are looking for git archive
. Maybe something like this:
$ git archive --format=tar --prefix=my-tag-or-commit-id/ my-tag-or-commit-id | (cd /path/to/repo/checkout && tar xf -)
Check git help archive
for other options and examples. You can use remote branch names for as well.
I hope this helps.
Upvotes: 4
Reputation: 67177
If you want to set your repo to the state (i.e. commit) of fa4ef34
, use git checkout
:
git checkout fa4ef34
This will bring your working copy to the state of fa4ef34
.
If you want to check out master
again, do a
git checkout master
However, if you're interested in a certain commit of a remote repo, you have to do it a bit different.
First, initialize a local repo:
git init myrepo
cd myrepo
Now, you are in your freshly created local repo. To get hands on the commits of a remote repo (for example the Bluetooth packet analyzer), you have to do the following:
git remote add bluez_hcidump git://git.kernel.org/pub/scm/bluetooth/bluez-hcidump.git
git fetch bluez_hcidump
Now, your repo knows everything about the bluez_hcidump
repo. If you want to access commit fa4ef34
that belongs to that repo, do the steps described at the beginning of my answer.
Upvotes: 1
Reputation: 72855
When you have a repository, you have all the revisions of all the files available to you. First you find the commit you're interested in using git log
. Then once you find out some way of referring to the commmit you're interested in, you can cut a branch starting from that commit using git branch branch_name <the commit you're interested in>
. Now you'll have a local branch (called branch_name
at that commit and you can git checkout branch_name
to see what things looked like at that time.
Upvotes: 1