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.
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
Yes you can do it absolutely.
Try something like this
Lets say you have cloned to
c:/originalRepository
switch to a new folder and say
git clone file:///c:/originalRepository
You will have your repo as cloned earlier.
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
}
你可以做一个新的分支
git checkout -b original-state REV
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.