John John - 6 months ago 59
Git Question

How to clone git repository with specific revision/changeset?

How can I clone git repository with specific revision, something like I usually do in Mercurial:

hg clone -r 3 /path/to/repository


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 repository's master branch to the commit of interest
git reset --hard FETCH_HEAD