git获取远端版本库上的Tag (没有clone[远端的版本库太大了])
方法一
http://stackoverflow.com/questions/25815202/git-fetch-a-single-commit
The git fetch
command delivers references (names, not raw commit-IDs) to the remote, more or less.
(More specifically, use git ls-remote remotename
to see what the remote is willing to give you in terms of names.
This produces a list of SHA-1s on the left with names on the right, and the only thing your fetch
can ask for is the names-on-the-right.
At which point you'll get the ID-on-the-left if the name on the remote still points to that ID, so it depends on how actively that remote gets updated.)
It is possible, in various ways, to deliver raw commit-IDs to a remote and ask that remote what is visible starting from that point,
and sometimes working backwards through history as well, but not via git fetch
.
(You can use git archive
but the remote can decide whether or not to allow you to access via raw commit-IDs;
or with remotes that have web server access, including to specific commits, you can often just view the top-level contents of a commit,
and use that to "drill down", as they say, to the various pieces. But that is a very slow way to do it.)
If you'd like to use git fetch
to get some particular commit, probably the easiest way to do that is to have someone with access to the remote attach a name—most likely a tag—to that commit ID.
Then you can have your git fetch
bring over that refspec, and put it under any other refspec you like.
For instance, suppose you can ssh directly to whatever hosts origin
:
$ ssh our.origin.host 'cd /repos/repo.git; git tag temporary f1e32e1'
[enter password, etc; observe tag created]
$ git fetch origin refs/tags/temporary:refs/heads/newbranch
[observe fetch happen; now you have local branch 'newbranch']
$ ssh our.origin.host 'cd /repos/repo.git; git tag -d temporary'
Note that the name need not be a branch, it need only be a reference you can pull over with git fetch
and see with git ls-remote
.
You then use a name that will match that on the left-hand-side of your refspec when fetching.
The name created in your repo is controlled by the right-hand-side of the refspec (refs/heads/newbranch
in the example above).
This is also the answer to your last paragraph question: you can only name things that have names on the remote (this is partly intended to avoid "leaking" unnamed commits that remain in a repository before garbage-collection, so it's considered a feature rather than a bug). These names go on the LHS of the refspec. Your own names go on the right.
Your name on the right is assumed to be a branch or tag name (based on what the name on the left matches, though you can explicitly spell out refs/heads/
or refs/tags/
to override it), so even though f1e32e1...
is a valid SHA-1, it's treated as a branch name here—the missing name on the left translates to HEAD
, as missing names almost always do—and git fetch
creates a branch whose name is disturbingly SHA-1-ish. (Incidentally I once created a branch name that looked like an SHA-1, and later confused myself. I forget exactly what the name was, something like de-bead
without the hyphen. I renamed it to the hyphenated version just to make it clear I didn't mean a raw commit ID! :-) )
貌似是无解的,远端必须给第一个commit起了名字,或者创建分支,或者Tag
才能通过fetch来获取
1. 本地初始化一个版本库
git init
2.添加远端
git remote add origin https://github.com/git/git.git
3.参照上面的链接处理
git ls-remote origin >origin.txt
把git ls-remote origin的结果输出到origin.txt的文件中
d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v0.99
$ git pull origin v0.99
remote: Counting objects: 4508, done.
remote: Compressing objects: 100% (234/234), done.
emote: Total 4508 (delta 1498), reused 1409 (delta 1409), pack-reused 2865R
Receivjects: 100% (4508/4508), 980.00 KiB | 334.00 KiB/s
ing objects: 100% (4508/4508), 1.08 MiB | 334.00 KiB/s, done.
Resolving deltas: 100% (3056/3056), done.
From https://github.com/git/git
* tag v0.99 -> FETCH_HEAD
error: Trying to write non-commit object d6602ec5194c87b0fc87103ca4d67251c76f233
a to branch refs/heads/master
fatal: Cannot update the ref 'HEAD'.
或者
git fetch origin v0.99
这个命令不会出错,但是本地没有代码,也找不到方法把代码弄出来。【因为本地一次提交都没有,是没有HEAD的】
$ git rev-list FETCH_HEAD --count
1076
//在版本0.99的时候,一共有1076次提交
$ git reset --hard d6602ec5194c87b0fc87103ca4d67251c76f233a 【这个也没啥用】
HEAD is now at a3eb250 [PATCH] alternate object store and fsck
//HEAD的指向和master的指向是一致的
8d530c4d64ffcc853889f7b385f554d53db375ed HEAD
//5个分支
ee6ad5f4d56e697c972af86cbefdf269b386e470 refs/heads/maint
8d530c4d64ffcc853889f7b385f554d53db375ed refs/heads/master
c07a1e8782dadcedeffd389aa9bce4fda5b0983c refs/heads/next
9b9e9adbccf975e4ffc7af213fbf55f187e752bf refs/heads/pu
49a1e5ee48904bfe562388041bdcdb3d8ad21d10 refs/heads/todo
//这些可能是合并记录
f0d0fd3a5985d5e588da1e1d11c85fba0ae132f8 refs/pull/10/head
3fed6331a38d9bb19f3ab72c91d651388026e98c refs/pull/10/merge
d604669e32e847c2ba5010c89895dd707ba45f55 refs/pull/100/head
1101dcb2eb2a20bb8009422d9760cd475c1b4590 refs/pull/100/merge
5867fc2ad19dd9dc49a9bde7704cf9cf7e539a78 refs/pull/101/head
a1fb527ff90f5df3bfb5d46e8ec5d05c66a1c824 refs/pull/101/merge
//这一串看起来似乎也是分支
6e41cb3e3fed66e67c91f92710be792ee001702a refs/remotes/github/html
cd2b8ae983a277fb3f3c2b2c6747b0a075af1421 refs/remotes/github/maint
e3cf854918ce6092220c9e9d43802b117618d3b5 refs/remotes/github/man
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/github/master
3be2039f06f131442a1ff8fe0759f05176d17143 refs/remotes/github/next
b4bcbacefc5233afca24b70b29448373293c8a4f refs/remotes/github/pu
4bee7490f9dab6e968086f7c3f1f2cc02caf91f3 refs/remotes/github/todo
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/origin/HEAD
5723afaf3a61cef537e1f4dfa88f8faf31060ef0 refs/remotes/origin/html
b15b5b10a75e202f3f90e000925545243267cbee refs/remotes/origin/maint
e193e4189407968b3c46992e3eac60d38424286e refs/remotes/origin/man
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/origin/master
5a144a28891926e235a49e4850b4ec5edb6db2cc refs/remotes/origin/next
55af6ac9def8b4fc2f65f627a84451d3bf17aa12 refs/remotes/origin/pu
4bee7490f9dab6e968086f7c3f1f2cc02caf91f3 refs/remotes/origin/todo
//gitgui tag
d5aef6e4d58cfe1549adef5b436f3ace984e8c86 refs/tags/gitgui-0.10.0
3d654be48f65545c4d3e35f5d3bbed5489820930 refs/tags/gitgui-0.10.0^{}
33682a5e98adfd8ba4ce0e21363c443bd273eb77 refs/tags/gitgui-0.10.1
729ffa50f75a025935623bfc58d0932c65f7de2f refs/tags/gitgui-0.10.1^{}
ca9b793bda20c7d011c96895e9407fac2df9648b refs/tags/gitgui-0.10.2
95dcfa3633004da0049d3d0fa03f80589cbcaf31 refs/tags/gitgui-0.10.2^{}
8c178f72b54f387b84388d093a920ae45b8659dd refs/tags/gitgui-0.11.0
1c1fe1005c9dacc05a34eb892ae20ebb1904a33b refs/tags/gitgui-0.11.0^{}
//junio tag
3a1c74404d544d20c0d1f0b9c072b471a20b04c0 refs/tags/junio-gpg-pub
7214aea37915ee2c4f6369eb9dea520aec7d855b refs/tags/junio-gpg-pub^{}
//v tag
d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v0.99
a3eb250f996bf5e12376ec88622c4ccaabf20ea8 refs/tags/v0.99^{}
f25a265a342aed6041ab0cc484224d9ca54b6f41 refs/tags/v0.99.1
78d9d414123ad6f4f522ffecbcd9e4a7562948fd refs/tags/v0.99.1^{}
c5db5456ae3b0873fc659c19fafdde22313cc441 refs/tags/v0.99.2
2779fad61302da0fe3a24995e343ab894f32fa42 refs/tags/v0.99.2^{}
方法二 仅仅检出Tag所对应的commit
http://stackoverflow.com/questions/20280726/how-to-git-clone-a-specific-tag 链接中的第二个方法
本地只有一个commit,无法用git status,git log,git branch
$ git clone -b v0.99 --depth 1 https://github.com/git/git.git
Cloning into 'git'...
remote: Counting objects: 243, done.
remote: Compressing objects: 100% (237/237), done.
rRemote: Total 243 (delta 17), reused 69 (delta 5), peceiving objects: 96% (234
Receiving objects: 98% (239/243), 220.00 KiB | 191.00 KiB/s
Receiving objects: 100% (243/243), 323.47 KiB | 191.00 KiB/s, done.
Resolving deltas: 100% (17/17), done.
Checking connectivity... done.
Note: checking out 'a3eb250f996bf5e12376ec88622c4ccaabf20ea8'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
===================方法二=============
方法三
http://stackoverflow.com/questions/20280726/how-to-git-clone-a-specific-tag 链接中的第一个方法
git clone --branch v0.99 https://github.com/git/git.git git5
这个不太可行,是先clone,然后再自动切换,还是把整个版本库弄下来了
===================方法三=============
方法四
http://stackoverflow.com/questions/791959/download-a-specific-tag-with-git
mkdir git6
cd git6
git init
git remote add origin https://github.com/git/git.git
提取Tag
d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v0.99
git fetch origin v0.99
$ git fetch origin v0.99
remote: Counting objects: 4508, done.
remote: Compressing objects: 100% (234/234), done.
rRemote: Total 4508 (delta 1498), reused 1409 (delta 1409), pack-reused 2865ecei
R
Receiving objects: 100% (4508/4508), 1.08 MiB | 503.00 KiB/s, done.
Resolving deltas: 100% (3056/3056), done.
From https://github.com/git/git
* tag v0.99 -> FETCH_HEAD
git tag v0.99 FETCH_HEAD
之后使用tortoisegit 切换到Tag v0.99
在这个目录下,各种命令好像都无法执行了。命令和文件的名字貌似重复了
先用tortoisegit在第一个commit上创建分支first 【其实可以直接创建成master】
切换到first分支,然后重命名分支为master
git branch -m first master
===2015年10月18日 凌晨一点更新===
实战二:linux系统的代码获取
1.在github上新建一个版本库LinuxStudy
2.然后clone到本地
3.git remote add torvalds https://github.com/torvalds/linux.git
4.git ls-remote origin >origin.txt
定位到的最小的Tag是 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
5.git fetch torvalds v2.6.11
remote: Counting objects: 18014, done.
remote: Compressing objects: 100% (4917/4917), done.
remote: Total 18014 (delta 484), reused 73 (delta 73), pack-reused 13024 eceivin
g objects: 100% (18014/18014), 49.82 MiB | 369.00 KiB/s
Receiving objects: 100% (18014/18014), 49.84 MiB | 369.00 KiB/s, done.
Resolving deltas: 100% (1699/1699), done.
From https://github.com/torvalds/linux
* tag v2.6.11 -> FETCH_HEAD
6.git tag v2.6.11 FETCH_HEAD
尝试checkout这个tag失败
重新fetch v2.6.12
$ git fetch torvalds v2.6.12
remote: Counting objects: 31617, done.
remote: Total 31617 (delta 0), reused 0 (delta 0), pack-reused 31616 eceiving ob
jects: 100% (31617/31617), 53.06 MiB | 273.00
Receiving objects: 100% (31617/31617), 53.13 MiB | 265.00 KiB/s, done.
Resolving deltas: 100% (13062/13062), done.
From https://github.com/torvalds/linux
* tag v2.6.12 -> FETCH_HEAD
$ git checkout v2.6.12
Checking out files: 100% (17360/17360), done.
Note: checking out 'v2.6.12'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 9ee1c93... Linux 2.6.12
git获取远端版本库上的Tag (没有clone[远端的版本库太大了])的更多相关文章
- 接着上一个版本在上一个分离access-token和ticket的版本
上代码: 本次修改将获取token和ticket分离出来,分别封装在函数中: 每个函数最后一个参数是一个回调参数: 回调函数的参数,是这一步中需要处理的结果; 结果怎么处理,根据传递进去的函数: va ...
- git上拉取tag,识别最新tag在此版本上新增tag
通过shell 脚本自动获取最新tag,并输入最新版本后,推到git上 # 拉取分支上现有的tags git fetch --tags echo -e "所有tag列表" git ...
- Windows下Git的下载、安装、设置用户名和邮箱、创建版本库等
Git官网:https://git-scm.com/ 一.Git下载 官网首页下载,当前最新版本:2.24.1 本人下载的是Git for Windows版本:Git-2.24.1.2-64-bit. ...
- Git tag push 到远端仓库
很早之前,我们就提到过用Git tag来给工程打上标签,但是这个命令只是在本地仓库打标签而已, 为了能把标签同步到远程服务器,我们可以这样做: 默认情况下,git push并不会把tag标签传送到远端 ...
- Git: git tag 使用小结(给发布版本打标记,切换并修改某个历史版本)
通常在软件发布的时候会打一个tag,用于标注这次发布的相关信息, 这样做的好处是,将来如果这个版本出现了问题,可以通过tag迅速定位到当前版本,进行错误修复. 1. 新建tag $ git tag v ...
- GIT回滚master分支到指定tag版本
master版本上线以后一般要打一个tag备份,以防事态有变,这是一个好习惯,如果以后有问题也可以放心的回滚版本,那么怎么用tag版本覆盖mastaer呢,其实只有几个命令 1.查看分支 git br ...
- git回滚到某个commit 上和 返回最新的版本git
1. 代码回退 首先你要用git log 查看你要回到的那个本版, 然后用 git reset --hard HEAD^ 回退到上个版本 git reset --hard commit_id 退到/进 ...
- Git 使用,本地项目上传到GitHub远程库
Git 使用,本地项目上传到GitHub远程库 环境 GitHub账号 点此进入github官网 git客户端工具 点此进入git下载页 本地项目上传到 GitHub 在GitHub中创建一个仓库(远 ...
- 3. git获取历史版本
1.使用gitbash进入git命令行,查看commit记录.操作如下: git log 1 2.找到你想提取的目标版本,复制对应的SHA值. 3.新建一个分支,操作如下: git branch 新分 ...
随机推荐
- 新安装Eclipse后的一些配置
配置护眼的背景色 Window-> Preferences-> General-> Editors-> Text Editors: Appearance color optio ...
- WPF FileFolderDialog 和弹出子窗口的一些问题
摘要:本文主要是WPF中 FileFolderDialog的相关问题,补充了关于在父窗口弹出子窗口,以及子窗口的相关属性(Data Binding)和命令绑定(Delegate Command)问题, ...
- 2016/7/6 神·CPU的人类极限在哪?
额,这其实是个搞怪贴 #include<stdio.h>int main(void){ int i,k; for(i=0;;i++) { k=i+222222222; printf(&qu ...
- How do I create an installation log?
Quote from: http://www.advancedinstaller.com/user-guide/qa-log.html Windows Installer logging Window ...
- 九度OJ 1366 栈的压入、弹出序列 【数据结构】
题目地址:http://ac.jobdu.com/problem.php?pid=1366 题目描述: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的 ...
- 【5】了解Bootstrap预置的栅格系统
在开篇之前我们来说2个class,因为以后要用到的 <div class="container"> ... </div> 用.container包裹页面上的 ...
- mysql 查看数据库大小
select table_schema, concat(truncate(sum(data_length)/1024/1024,2),' mb') as data_size,concat(trunca ...
- (转载)Delphi开发经验谈
Delphi开发经验谈 开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件. ...
- ImportError: No module named pysqlite2 --安装pysqlite
yum install sqlite-devel -y pip install pysqlite 每次使用yum安装额外的包之后都需要重新安装python,否则可能会有各种奇奇怪怪的问题出现 cd P ...
- jquery实现替代iframe的功能
使用iframe能很好的嵌入其他的网页或者网站,但是iframe每次加载都会浪费好多的时间,且会阻止其他元素的加载,搜索引擎也不能识别页面ifram框架中被调用的链接.文本.图片等等内容的. Html ...