tags:

views:

76

answers:

4

Hi,

I am very new to the world of git and version control.

I cloned a remote git repository about a month ago. The remote repository has undergone many changes and has now become unstable.

Now I need another copy of the repository, version identical to the one I cloned a month ago. How do I do this?

Thank you.

+3  A: 

You could "reset" your repository to any commit you want (e.g. 1 month ago).

Use git-reset for that:

git clone [remote_address_here] my_repo
cd my_repo
git reset --hard [ENTER HERE THE COMMIT HASH YOU WANT]
Rui Carneiro
You didn't mention it, but this will only reset the `master` branch, which is checked out by default on a clone. If a branch other than `master` is your main development branch that must be checked out first before `git reset`
Steve Folly
@Steve true! +1
Rui Carneiro
+1  A: 

Use git log to find the revision you want to rollback to, and take note of the commit hash. After that, just git checkout <hash>. Example:

$ git log
commit 89915b4cc0810a9c9e67b3706a2850c58120cf75
Author: Jardel Weyrich <suppressed>
Date:   Wed Aug 18 20:15:01 2010 -0300

    Added a custom extension.

commit 4553c1466c437bdd0b4e7bb35ed238cb5b39d7e7
Author: Jardel Weyrich <suppressed>
Date:   Wed Aug 18 20:13:48 2010 -0300

    Missing constness.

$ git checkout 4553c1466c437bdd0b4e7bb35ed238cb5b39d7e7
Note: moving to '4553c1466c437bdd0b4e7bb35ed238cb5b39d7e7'
which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b <new_branch_name>
HEAD is now at 4553c14... Missing constness.

That way you don't lose any informations, thus you can move to a newer revision when it becomes stable. Note this will not allow you to commit at this same point. If you wish so, create a new branch as mentioned on the message printed above.

jweyrich
But also nothe that you are on a detached head, which is OK for read only operations. But when you intend to make changes starting at this revision, you need to create a new branch. See http://sitaramc.github.com/concepts/detached-head.html for more informations.
Rudi
@Rudi: Thank you. It was just an example to show the usage. Updated to mention it.
jweyrich
A: 

The source tree you are requiring is still available within the git repository, however, you will need the SHA1 of the commit that you are interested in. I would assume that you can get the SHA1 from the current clone you have?

If you can get that SHA1, the you can create a branch / reset there to have the identical repository.

Commands as per Rui's answer

gpampara
A: 

Unlike centralized version control systems, Git clones the entire repository, so you don't only get the current remote files, but the whole history. You local repository will include all this.

There might have been tags to mark a particular version at the time. If not, you can create them yourself locally. A good way to do this is to use git log or perhaps more visually with tools like gitk (perhaps gitk --all to see all the branches and tags). If you can spot the commits hashes that were used at the time, you can tag them using git tag <hash> and then check those out in new working copies (for example git checkout -b new_branch_name tag_name or directly with the hash instead of the tag name).

Bruno