我无法克隆git树 [英] I cannot clone git tree
问题描述
我对git有疑问,我试图克隆一棵树,但没有成功.
I have a question about git, I tried to clone a tree but without success.
git clone https://github.com/cer/event-sourcing-examples/tree/d2077e21aa677a00095f90250470ff011c132ab8/java-spring
我克隆了项目
git clone https://github.com/cer/event-sourcing-examples
我试图切换到那棵树,但没有效果
and I tried to switch to that tree but no effect
您有什么建议吗?
最诚挚的问候
推荐答案
Git无法直接克隆树.您需要克隆整个存储库,然后签出使用所需树的提交.不过,为了减少混乱,请注意,树"和提交"之间有区别,
Git cannot clone a tree directly. You need to clone the entire repository, and then check out a commit that uses the tree you want. For the sake of reducing confusions, though, do note that there is a difference between the terms "tree" and "commit", though:
- 树是代表目录的Git对象,并包含指向Blob(文件)和其他树的链接.树不一定是存储库的根目录.
- 提交对象包含到存储库的 root 树的链接,以及一些其他信息,例如提交消息,日期和其他标头.
- A tree is a Git object representing a directory, and contains links to blobs (files) and other trees. A tree is not necessarily the root directory of the repository.
- A commit object contains a link to the root tree of the repository, and some extra information such as commit message, dates and other headers.
您只能检出提交.很少有Git命令直接处理树对象(git cat-file
和git ls-tree
是例外).但是,GitHub URL中的对象ID确实是提交的ID,所以这不是问题.
You can only check out commits. Few Git commands deal directly with tree objects (git cat-file
and git ls-tree
being among the exceptions). However, the object ID in your GitHub URL is indeed the ID of a commit, so that's not a problem.
然后,您可以做的就是在克隆存储库之后将想要的提交检入新分支:
What you can do, then, is check out the commit you want into a new branch after you've cloned the repository:
git checkout -b test-branch d2077e21
如果您要解决的问题只是从远程存储库中获取单个提交(或树),那么您就不走运了,因为Git的远程协议不支持该操作.如果有的话,如果您可以在所需的提交中将分支插入远程存储库,则可以直接克隆该分支,而无需任何历史记录:
If the problem you're trying to solve is just fetching a single commit (or tree) from a remote repository, then you're out of luck, because Git's remote protocol does not support that operation. If anything, if you can insert a branch into the remote repository at the commit you want, you can clone that branch directly, without any history:
git clone -b test-branch --depth 1 https://github.com/cer/event-sourcing-examples
但是,如果您不能做到这一点,那么您仍然不走运.远程协议仅允许引用命名的ref,而不是任意提交.
If you can't do that, however, then you're still out of luck. The remote protocol only allows referencing named refs, not arbitrary commits.
这篇关于我无法克隆git树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!