在 git 中克隆一棵树
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19601642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cloning a tree in git
提问by M J
I am new to git.
我是 git 新手。
I have accidentally removed part of the history for our project on git. Now, I want to set the head to the latest stable release. The issue is the tree to which i want to set the HEAD to is not accessible from it commands, but i can access it through browser.
我在 git 上不小心删除了我们项目的部分历史记录。现在,我想将头部设置为最新的稳定版本。问题是我想将 HEAD 设置为的树无法从它的命令访问,但我可以通过浏览器访问它。
Does anybody know how to clone a specific tree using its SHA?
有人知道如何使用 SHA 克隆特定树吗?
I have tried git reset SHA, but the SHA is not recognized.
I have also tried git clone -b SHA repo.git
, but it did not work either.
我试过 git reset SHA,但无法识别 SHA。我也试过git clone -b SHA repo.git
,但也没有用。
回答by michas
You mix up different concepts.
你混淆了不同的概念。
Whenever you clone, you clone a whole repository. (There is no way to clone a specific "tree".)
每当您克隆时,您就克隆了整个存储库。(无法克隆特定的“树”。)
A repository mainly consist of many commits. Those are the ones you can checkout. Each commit knows its parent commit - this forms a history tree.
一个存储库主要由许多提交组成。那些是你可以结帐的。每个提交都知道它的父提交——这形成了一个历史树。
A commit itself contains a directory treewith all the files.
提交本身包含一个包含所有文件的目录树。
Usually there is some kind of server hosting the "central" repository.
通常有某种服务器托管“中央”存储库。
You first clone your repository. This will create a complete copy of that central repository on your host. (With all the branches and commits.)
您首先克隆您的存储库。这将在您的主机上创建该中央存储库的完整副本。(所有分支和提交。)
Afterwards you usually only interact with your local repository.
之后,您通常只与本地存储库交互。
From you error message (unfortunately hidden only in some comment) it seems like your projects might use submodules. (A way of including a completely different repository in your project.)
从您的错误消息(不幸的是仅在某些评论中隐藏),您的项目似乎可能使用子模块。(一种在项目中包含完全不同的存储库的方法。)
This tends to be a bit tricky. Have a look at http://git-scm.com/book/en/Git-Tools-Submodules.
回答by thameera
Has this "latest stable release" already pushed to the server? If yes, you can run a git fetch
and git checkout SHA
.
这个“最新的稳定版本”已经推送到服务器了吗?如果是,您可以运行 a git fetch
and git checkout SHA
。
If this particular commit is only in your local history, do a git reflog
and identify the commit. Then checkout the desired commit.
如果此特定提交仅在您的本地历史记录中,请执行git reflog
并识别该提交。然后签出所需的提交。