Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a tree in git

Tags:

git

clone

tree

I am new to 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.

Does anybody know how to clone a specific tree using its 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.

like image 640
M J Avatar asked Dec 19 '22 22:12

M J


2 Answers

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.

like image 50
michas Avatar answered Jan 01 '23 22:01

michas


Has this "latest stable release" already pushed to the server? If yes, you can run 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.

like image 33
thameera Avatar answered Jan 01 '23 22:01

thameera