views:

62

answers:

3

Could anyone tell me how to clone the first commit? I don't want to delete recent commits, just make a clone copy of the initial state so I can grab some of the files.

A: 

I would just do a

git clone [repo name]

then a

git reset --hard[revision]

See http://www.kernel.org/pub/software/scm/git/docs/git-reset.html

It will get you where you want to go. may transfer more code than what you are looking to do, but it is what comes to mind... hope it helps

bwawok
A: 

To answer the question I think you meant to ask:

You can get your entire repository into the state of the first commit with:

git checkout <commit SHA1>

After you're done messing around, you can do git checkout master to get back to where you were.

And you can get individual files into their state from the first commit with:

git checkout <commit SHA1> <file or directory> ...

Again, after you're done, you can do git checkout master <file or directory> to get back to where you were.

There's no need to "clone" a commit (by which I assume you mean clone the repository, and check out the first commit?). Of course, if for some reason you couldn't bear to modify any files in your repository (e.g. don't want to make your build out of date) you could of course clone it, then do the exact same thing in the cloned repo.

Jefromi
A: 

I think all you need to do is create a new branch from the original commit you want, check that out, and then merge back into the HEAD of the branch you're working on.

If abcxyz... is the SHA1 of the commit you want and you're working in the master branch, this is generally what you'd want to do:

git branch oldskool abcxyz... # creates a new branch called oldskool from the commit
git checkout oldskool
#make changes
git rebase master #bring the oldskool branch up to the HEAD of the master branch (shouldn't overwrite the changes in the files you edited)
git checkout master
git merge oldskool
Bryce
You're creating oldskool from an ancestor of master, so the rebase is just going to fast-forward it, and then the merge is a no-op. No change to master. If you skip the rebase, the merge will also be a fast-forward, and again, no change to master.
Jefromi