我如何用特定的版本克隆git存储库,就像我通常在Mercurial中做的那样:
hg clone -r 3 /path/to/repository
我如何用特定的版本克隆git存储库,就像我通常在Mercurial中做的那样:
hg clone -r 3 /path/to/repository
当前回答
对于单个文件,当提交号已知时,可以使用wget onliner:
wget https://raw.githubusercontent.com/torvalds/linux/896066ee1cf4d653057dac4e952f49c96ad16fa7/README
其他回答
克隆一个git存储库,恰当地说,就是克隆整个存储库:没有办法只选择一个修订版本来克隆。然而,一旦你执行了git克隆,你可以通过执行checkout <rev>来检出一个特定的修订。
总结一下(git v. 1.7.2.1):
在你想要回购的地方做一个常规的git克隆(得到所有的日期-我知道,不是想要的,我们正在那里) Git checkout <sha1 rev>你想要的rev Git重置——很难 Git checkout -b master
在一个特定的分支或标签上只克隆一个特定的提交:
git clone --depth=1 --branch NAME https://github.com/your/repo.git
不幸的是,NAME只能是分支名称或标记名称(不能提交SHA)。
省略——depth标志来下载整个历史记录,然后签出分支或标记:
git clone --branch NAME https://github.com/your/repo.git
这适用于最新版本的git(我使用2.18.0版本)。
mkdir linux-4.3.20151106
cd linux-4.3.20151106/
git init
git fetch git@github.com:torvalds/linux.git 9154301a47b33bdc273d8254c407792524367558
error: unknown option `no-write-fetch-head'
usage: git fetch [<options>] [<repository> [<refspec>...]] or: git fetch [<options>] <group>
or: git fetch --multiple [<options>] [(<repository> | <group>)...] or: git fetch --all [<options>]
git --version
git version 2.17.1
export https_proxy=http://192.168.1.3:1080;export http_proxy=http://192.168.1.3:1080
add-apt-repository ppa:git-core/ppa
apt update
apt-get install --only-upgrade git
git --version
git version 2.38.0
git fetch git@github.com:torvalds/linux.git 9154301a47b33bdc273d8254c407792524367558 --no-write-fetch-head --depth=1
remote: Enumerating objects: 54692, done.
remote: Counting objects: 100% (54692/54692), done.
remote: Compressing objects: 100% (50960/50960), done.
remote: Total 54692 (delta 3828), reused 29210 (delta 2966), pack-reused 0
Receiving objects: 100% (54692/54692), 147.35 MiB | 2.85 MiB/s, done.
Resolving deltas: 100% (3828/3828), done.
git branch master 9154301a47b33bdc273d8254c407792524367558
git checkout
# clone special tag/branch without history
git clone --branch=<tag/branch> --depth=1 <repository>
# clone special revision with minimal histories
git clone --branch <branch> <repository> --shallow-since=yyyy-MM-ddTHH:mm:ss # get the commit time
cd <dir>
git reset --hard <revision>
如果不设置uploadpack,就不能获得没有历史记录的修订。在服务器端allowReachableSHA1InWant=true,而您可以为它创建一个标记并克隆特殊标记。