Search code examples
gitgit-clonegit-revert

Can we reclone a git repository from the existing local repository


Since git is a distributed VCS, it should have complete history of changes done to a repository.

So can we extract that version of repo which was cloned first?

Actually I have done a lot of changes in my existing local repo. and do not want to revert back to the original state by losing the data. But I want to extract the original repository(which I cloned initially) to some other location using existing git objects(blob/tree).

Note : I don't have the access to git server now.


Solution

  • Try this:

    git clone SOURCE_PATH NEW_PATH # clones everything you have committed up to now
    cd NEW_PATH                    # go to new clone, don't modify the pre-existing one
    git reset --hard REV           # REV is the revision to "rewind" to (from git log)
    

    So you need to figure out explicitly which revision to go back to (Git probably doesn't know which revision you originally cloned, but probably you can figure it out). The first step is just to clone from your local disk to your local disk in a different directory so you can keep your existing work untouched.