大约一个月前,我克隆了一个远程git存储库。远程存储库经历了许多更改,现在变得不稳定了。现在我需要存储库的另一个副本,与我一个月前克隆的版本相同。
我怎么做呢?
大约一个月前,我克隆了一个远程git存储库。远程存储库经历了许多更改,现在变得不稳定了。现在我需要存储库的另一个副本,与我一个月前克隆的版本相同。
我怎么做呢?
当前回答
与集中式版本控制系统不同,Git克隆整个存储库,因此您不仅可以获得当前的远程文件,还可以获得整个历史。您的本地存储库将包括所有这些。
There might have been tags to mark a particular version at the time. If not, you can create them yourself locally. A good way to do this is to use git log or perhaps more visually with tools like gitk (perhaps gitk --all to see all the branches and tags). If you can spot the commits hashes that were used at the time, you can tag them using git tag <hash> and then check those out in new working copies (for example git checkout -b new_branch_name tag_name or directly with the hash instead of the tag name).
其他回答
与集中式版本控制系统不同,Git克隆整个存储库,因此您不仅可以获得当前的远程文件,还可以获得整个历史。您的本地存储库将包括所有这些。
There might have been tags to mark a particular version at the time. If not, you can create them yourself locally. A good way to do this is to use git log or perhaps more visually with tools like gitk (perhaps gitk --all to see all the branches and tags). If you can spot the commits hashes that were used at the time, you can tag them using git tag <hash> and then check those out in new working copies (for example git checkout -b new_branch_name tag_name or directly with the hash instead of the tag name).
你可以这样求解:
git reset --hard sha
例如:85a108ec5d8443626c690a84bc7901195d19c446
您可以通过以下命令获取所需的sha:
git log
你可以“重置”你的存储库到任何你想要的提交(例如1个月前)。
使用git-reset:
git clone [remote_address_here] my_repo
cd my_repo
git reset --hard [ENTER HERE THE COMMIT HASH YOU WANT]
也许git重置可以解决你的问题。
git reset --hard -#commit hash-
如果你需要获取的版本不是分支就是标签,那么:
git clone -b branch_or_tag_name repo_address_or_path