shealtiel
shealtiel

Reputation: 8388

Fetching a specific GIT revision to my local repository

I'll start from saying that I've using mainly SVN and our project moved recently to Git. I figure out that I don't really understand lot of GIT principles.

My question is practical:

We have a GIT repo hosted on a central place (Beanstalk) and all of us push and pull there.
Now, my local repo got broken, and I need to recreate it. But not the latest revision but a specific one in the past (bc213be6, just an example).

How can I accomplish this?
I would clone the central repository but, as I said above, I need the none latest version.

Thanks

Gidi

Upvotes: 2

Views: 1061

Answers (2)

VonC
VonC

Reputation: 1323115

Cloning will get you the full history. Then you can choose any revision you want to see in your working tree.

Rather than a reset, I would do a git checkout to the right ('bc213be6' for instance, or the right tag if there is one):

git clone git://git.myserver.org/myrepo.git
cd myrepo
git checkout <sha1>

But if you want to do any modification, create a local branch:

git checkout -b myBranch <sha1>

If you don't, you would be in a DETACHED HEAD.

Note that you have many way to specify your revision, as explained in git rev-parse.

Upvotes: 2

Hazok
Hazok

Reputation: 5583

Do a git clone first. Afterwards use a git reset to move HEAD to the commit you want.

Here's the link to the git manual for the reset: http://git-scm.com/docs/git-reset

Upvotes: 2

Related Questions