之前已经可以下载git上的最新版本的代码了:
现在需要去下载之前的版本:
git clone specific version
git 下载 指定版本
如何在 GitHub 下载某个程序的特定版本(代码)? – GitHub – 知乎
licrifandeMacBook-Pro:test_jiandao crifan$ pwd /Users/crifan/dev/tmp/test_jiandao licrifandeMacBook-Pro:test_jiandao crifan$ git clone https://git.oschina.net/windoze/jidservice Cloning into ‘jidservice’… remote: Counting objects: 2648, done. remote: Compressing objects: 100% (1974/1974), done. remote: Total 2648 (delta 1203), reused 201 (delta 75) Receiving objects: 100% (2648/2648), 3.72 MiB | 815.00 KiB/s, done. Resolving deltas: 100% (1203/1203), done. Checking connectivity… done. licrifandeMacBook-Pro:test_jiandao crifan$ git log fatal: Not a git repository (or any of the parent directories): .git licrifandeMacBook-Pro:test_jiandao crifan$ |
GIT如何取下以前的版本库-CSDN论坛-CSDN.NET-中国最大的IT技术社区
Git clone particular version of remote repository – Stack Overflow
How to clone git repository with specific revision/changeset? – Stack Overflow
然后去此处的,oschina上面的git的中某次提交的SHA1的值:
原来自己搞错了:
此处需要进入子目录,才能git看log:
licrifandeMacBook-Pro:test_jiandao crifan$ git reset –hard 9c215b35f fatal: Not a git repository (or any of the parent directories): .git licrifandeMacBook-Pro:test_jiandao crifan$ pwd /Users/crifan/dev/tmp/test_jiandao licrifandeMacBook-Pro:test_jiandao crifan$ ls iOS-Client licrifandeMacBook-Pro:test_jiandao crifan$ cd iOS-Client/ licrifandeMacBook-Pro:iOS-Client crifan$ git log commit d97f138c0f72090f5fdbec4df337e7523df8775c Date: Mon Jan 4 21:44:36 2016 +0800 modifying code for support chat message show file, not complete yet, just can compile now commit 9c215b35f4577bbede16802a3d18ce2a03464e25 Date: Sat Jan 2 20:17:42 2016 +0800 can read contact to add private friend commit fbb406e9059056426f23c7505aa3016611486cbb Date: Sat Jan 2 18:03:03 2016 +0800 can read phone contact then add to colleague commit 2da57d6a44063586282fb12e9a246f7ed4865970 Date: Fri Jan 1 23:59:32 2016 +0800 debugging for support read phone contact list commit adcee2a1a85060a20f32b61c2b9b61b1a1a8d77a Date: Fri Jan 1 15:34:37 2016 +0800 from add drop down list to create group is ok commit 50be6e1711d6ac728260e1da6cb69ad13ba0d3a0 licrifandeMacBook-Pro:iOS-Client crifan$ |
然后,本地git,强制恢复到之前的某个版本:
licrifandeMacBook-Pro:iOS-Client crifan$ git reset –hard 9c215b35f HEAD is now at 9c215b3 can read contact to add private friend licrifandeMacBook-Pro:iOS-Client crifan$ |
就可以了。
[总结]
用git下载服务器上某个版本:
1.先下载最新版本
2.进入子目录中,去看之前的log,之前有哪些版本:
cd iOS-Client/ git log |
就可以看到之前的各个版本的SHA1值了,比如其中一个版本是:
commit 9c215b35f4577bbede16802a3d18ce2a03464e25 Author: crifan <[email protected]> Date: Sat Jan 2 20:17:42 2016 +0800 can read contact to add private friend |
其中此处的OSChina中网页版Git中也可以看到对应的版本:
版本-》提交纪录-》
3.用git reset到对应的版本:
git reset –hard 9c215b35f |
其中的9c215b35f是SHA1值的前面的几位(一般是9位或10位),只要确保唯一即可。
当然,也可以使用完整的SHA1的值:9c215b35f4577bbede16802a3d18ce2a03464e25
对应输出是:
licrifandeMacBook-Pro:iOS-Client crifan$ git reset –hard 9c215b35f HEAD is now at 9c215b3 can read contact to add private friend licrifandeMacBook-Pro:iOS-Client crifan$ |
此时,即可实现了:
下载git服务器中,对应的版本为9c215b35f4577bbede16802a3d18ce2a03464e25的代码了。
4.如果还想要,此处本地,恢复到最新的版本,则可以再去:
git pull |
即可下载,恢复到,和服务器中一样的,最新的版本了。
转载请注明:在路上 » [已解决]下载git中之前的某个版本