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.
About cloning a repository You can clone a repository from GitHub.com to your local computer to make it easier to fix merge conflicts, add or remove files, and push larger commits. When you clone a repository, you copy the repository from GitHub.com to your local machine.
You first have to get the original Git repository on your machine. Then, go into the repository. Finally, use the --mirror flag to copy everything in your local Git repository into the new repo.
Usage. git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git 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 stashgit 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 repocd ..
clonegit 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 agit log
and reset it to the desired SHAgit reset --hard SHA
And finally you can go back to your local_repo_1
and apply your stashgit 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
You can add this script to your bash
reclone () {
set -e
basename=${PWD##*/}
remoteurl=$(git remote get-url --push origin)
cd ..
echo $basename
echo $remoteurl
rm -rf $basename
git clone $remoteurl
cd $basename
set +e
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With