如何克隆具有特定版本/变更集的git存储库? [英] How to clone git repository with specific revision/changeset?
本文介绍了如何克隆具有特定版本/变更集的git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hg clone -r 3我该如何克隆具有特定版本的git存储库,就像我通常在Mercurial中做的那样: / path / to / repository
解决方案
UPDATE for git versions> 1.7使用git clone和git reset,如Vaibhav Bajpai的回答中所述如果您不想获取完整的存储库,那么您可能不应该使用 clone
。您始终可以使用提取来选择要提取的分支。我不是hg专家,所以我不知道 -r
的细节,但是在git中你可以做这样的事情。
#在当前目录中创建一个新的空白存储库
git init
#添加远程
git remote add origin url:// to / source / repository
#获取感兴趣的提交(或分支或标记)
#注意:此提交的完整历史记录将被检索
git fetch origin<感兴趣的提交>
#将这个存储库的主分支重置为感兴趣的提交
git reset --hard FETCH_HEAD
How can I clone git repository with specific revision, something like I usually do in Mercurial:
hg clone -r 3 /path/to/repository
解决方案
UPDATE for git versions > 1.7 use git clone and git reset, as described in Vaibhav Bajpai's answer
If you don't want to fetch the full repository then you probably shouldn't be using clone
. You can always just use fetch to choose the branch that you want to fetch. I'm not an hg expert so I don't know the details of -r
but in git you can do something like this.
# make a new blank repository in the current directory
git init
# add a remote
git remote add origin url://to/source/repository
# fetch a commit (or branch or tag) of interest
# Note: the full history of this commit will be retrieved
git fetch origin <sha1-of-commit-of-interest>
# reset this repository's master branch to the commit of interest
git reset --hard FETCH_HEAD
这篇关于如何克隆具有特定版本/变更集的git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文