我如何用特定的版本克隆git存储库,就像我通常在Mercurial中做的那样:
hg clone -r 3 /path/to/repository
我如何用特定的版本克隆git存储库,就像我通常在Mercurial中做的那样:
hg clone -r 3 /path/to/repository
当前回答
$ git clone $URL
$ cd $PROJECT_NAME
$ git reset --hard $SHA1
再次返回到最近的提交
$ git pull
为了在线(远程)保存还原的提交,你必须强制执行origin:
git push origin -f
其他回答
你可以简单地使用git checkout <commit hash>
在这个序列中
bash git克隆[URLTORepository] Git checkout [commit]
提交哈希看起来像这样“45ef55ac20ce2389c9180658fdba35f4a663d204”
总结一下(git v. 1.7.2.1):
在你想要回购的地方做一个常规的git克隆(得到所有的日期-我知道,不是想要的,我们正在那里) Git checkout <sha1 rev>你想要的rev Git重置——很难 Git checkout -b master
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
$ git clone $URL
$ cd $PROJECT_NAME
$ git reset --hard $SHA1
再次返回到最近的提交
$ git pull
为了在线(远程)保存还原的提交,你必须强制执行origin:
git push origin -f
如果你的意思是你想要从开始到某一点的所有东西,查尔斯·贝利的答案是完美的。如果你想做相反的事情,并从当前日期检索历史的子集,你可以使用git clone——depth [N],其中N是你想要的历史的转速。然而:
——深度 创建一个浅克隆,其历史记录被截断为指定的修订数。浅存储库有许多限制(您不能从它复制或获取,也不能从它推入或进入它),但如果您只对具有较长历史的大型项目的最近历史感兴趣,并且希望以补丁的形式发送修复,那么浅存储库就足够了。