How can I clone git repository with specific revision/changeset? Something like I usually do in Mercurial: hg clone -r 3 /path/to/repository
Thanks!
How can I clone git repository with specific revision/changeset? Something like I usually do in Mercurial: hg clone -r 3 /path/to/repository
Thanks!
Cloning a git repository, aptly, clones the entire repository: there isn't a way to select only one revision to clone. However, once you perform git clone
, you can checkout a specific revision by doing checkout <rev>
.
If you don't want to fetch the full repository then you probably shouldn't be using clone
. You can always just use fetch to choose the branch that you want to fetch. I'm not an hg expert so I don't know the details of -r
but in git you can do something like this.
# make a new blank repository in the current directory
git init
# add a remote
git remote add origin url://to/source/repository
# fetch a commit (or branch or tag) of interest
# Note: the full history of this commit will be retrieved
git fetch origin <sha1-of-commit-of-interest>
# reset this repositories master branch to the commit of interest
git reset --hard FETCH_HEAD
If you mean you want to fetch everything from the beginning up to a particular point, Charles Bailey's answer is perfect. If you want to do the reverse and retrieve a subset of the history going back from the current date, you can use git clone --depth [N]
where N is the number of revs of history you want. However:
--depth
Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.