Take the 2-minute tour ×

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.



share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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

share|improve this answer
It's unlikely that git reset is what the questioner wants - as VonC says you can move about between old versions with git checkout without changing the position of any branch (as git reset would). –  Mark Longair Mar 30 '11 at 5:22
Both appear to accomplish what the questioner wants. From what the user mentioned, he wants a new local repo with a branch with a previous commit from the central repo. That could be accomplished by the reset or the checkout, however with the checkout you need to create a copy of the branch first to avoid the detached HEAD state. With a reset, there's no need of creating another local branch. –  Hazok Mar 30 '11 at 21:57
So in essence, there's more overhead with the checkout than the reset... –  Hazok Mar 30 '11 at 22:01
And still satisfies questioner's wants... –  Hazok Mar 30 '11 at 22:01

Your Answer


