简体   繁体   English

在git中克隆树

[英]Cloning a tree in git

I am new to git. 我是git的新手。

I have accidentally removed part of the history for our project on git. 我不小心删除了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. 问题是无法从其命令访问将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. 我尝试了git reset SHA,但是无法识别SHA。 I have also tried git clone -b SHA repo.git , but it did not work either. 我也尝试了git clone -b SHA repo.git ,但是也没有用。

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 tree with 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 . 看看http://git-scm.com/book/en/Git-Tools-Submodules

Has this "latest stable release" already pushed to the server? 这个“最新的稳定版本”已经推送到服务器了吗? If yes, you can run a git fetch and git checkout SHA . 如果是,则可以运行git fetchgit checkout SHA

If this particular commit is only in your local history, do a git reflog and identify the commit. 如果此特定提交仅在您的本地历史记录中,请执行git reflog并标识该提交。 Then checkout the desired commit. 然后签出所需的提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM