从私人GitHub存储库签出标签 [英] Checkout a tag from a private GitHub repository
问题描述
我需要从GitHub克隆一个私有存储库,但我只想获得一个特定的标签(所以基本上,克隆实际上是它的错误术语)。
现在,问题是有多种选择,并且所有这些选项都无法实现:
curl
或 wget
访问(至少我不能弄清楚如何)。
git clone
,然后运行 git checkout
来获取标签指定的版本,但是我下载的版本比我需要的要多,我处于分离状态,剩下的东西都保留在磁盘上。当然,我可以手动清理它,但是......好吧,很多工作都是为了一项简单的任务。
什么是最好的方法以达到我想要做的事情?
更新
我认为我的问题不够清楚,因此我添加一些更多的信息:我想要的不仅仅是达到标记所标记的修订版,而且我还想删除整个历史记录。基本上,就好像Git从来没有存在过,而我所拥有的只是这个单一版本的代码。任何提示?
我认为可以通过 git clone --single-branch
:
- [no-] single-分支
仅克隆通向单个分支尖端的历史记录,或者由--branch选项指定的
或主分支远程的HEAD
指向的历史记录。使用--depth选项创建浅表副本时,此
是缺省值,除非给出了--no-single-branch来获取所有分支尖端附近的
历史记录。进一步获取到
生成的存储库将仅更新
分支的远程跟踪分支,该选项用于初始克隆。如果
remote的HEAD在创建单分支克隆时未指向任何分支,则
不会创建远程跟踪分支。
请注意,这表示您需要使用指定分支 - 分支
,而不是标签。但是, - branch
的文档说:
--branch,-b
代替将新创建的HEAD指向克隆仓库HEAD指向的分支,而是指向分支。在
非裸仓库中,这是将被检出的分支。
--branch还可以在
生成的存储库中提交标签并分离HEAD。
最后一句说明您可以使用 - branch
带有标签。我唯一不确定的是你是否可以使用 - 单分支
并将标签传递给 - 分支
。我想你将不得不尝试确认。或者,您必须在远程存储库中创建分支,而不是标签。
更新
你现在说你也想摧毁整个历史。
两种方式:
危险地生活:
git clean -xdf#清除所有不在git
rm -rf .git#remove git
git init。 #把它放回
git add。 #添加所有文件
git commit -a -m一尘不染的永恒阳光
<生活不那么危险
git rebase --root -i#需要最近版本的git
然后将每行改为以 s
开头,以压缩到原始提交。 / p>
另请参阅如何将所有git提交压缩成一个?
I need to clone a private repository from GitHub, but I only want to get a specific tag (so basically, cloning is actually the wrong term for it).
Now, the problem is that there are multiple options, and all of them don't really work out:
- GitHub offers tagged versions as archives, but they are not accessible via
curl
orwget
(at least I could not figure out how). - GitHub does not support archiving repositories.
- I could run a
git clone
and then run agit checkout
to get to the version specified by the tag, but then I download more than I need, I am in detached head state, and all the remaining stuff stays on disk. Of course, I could clean this up manually, but … well, lots of work for a trivial task.
What is the best way to achieve what I want to do?
Update
I think my question was not clear enough, hence I'm adding some more information: What I want is not only get to the revision marked by a tag, but I also want to remove the entire history. Basically, as if Git never existed, and all I ever had was this one single version of my code. Any hints?
I think you can do this with git clone --single-branch
:
--[no-]single-branch Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.
Note that this says you need a branch to be specified with --branch
, rather than a tag. However, the documentation for --branch
says:
--branch , -b Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
The last sentence says you can use --branch
with a tag. The only thing I'm not sure of is whether you can both use --single-branch
and pass a tag to --branch
. I guess you will have to try that to confirm. Alternatively, you will have to create a branch in the remote repository as opposed to a tag.
Update
You now say you also want to destroy the entire history. Do this afterwards.
Two ways:
Living dangerously:
git clean -xdf # Clean out everything not in git
rm -rf .git # remove git
git init . # put it back
git add . # Add all the files
git commit -a -m "Eternal sunshine of the spotless mind"
Living less dangerously
git rebase --root -i # needs recent version of git
then change every line to begin with s
to squash into the original commit.
Also see How to squash all git commits into one?
这篇关于从私人GitHub存储库签出标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!