2

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
shealtiel
  • 8,020
  • 18
  • 50
  • 82

2 Answers2

2

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

Hazok
  • 5,373
  • 4
  • 38
  • 48
  • It's unlikely that `git reset` is what the questioner wants - [as VonC says](http://stackoverflow.com/questions/5480285/fetching-a-specific-git-revision-to-my-local-repository/5481810#5481810) 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 05: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
2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250