Can we reclone a git repository from the existing local repository
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.
If I understand correctly, you cloned your project from a remote repo (call the local repo - local_repo_1
), after that you have made some changes to it (uncommited) and now you want to have another copy of the original cloned git repo, but from the local_repo_1
and not from remote.
You can do this in the following these steps:
Save your work in a stash
git stash save stash_name //give any name to your stash, say local_repo_2
Now you'd be left with the bare repo that you cloned from the remote, you can clone it by:
move out from your git repo
cd ..
clone
git clone /path/to/local_repo_1 local_repo_2 // local_repo_2 is the new repo
In case you had some local commits too, then do a
git log
and reset it to the desired SHA
git reset --hard SHA
And finally you can go back to your
local_repo_1
and apply your stash
git stash apply
Voila, now you have:
local_repo_1: your changes that you had made over and above the bare repo, back to its original form.
local_repo_2: a copy of the remote repo without your local changes