Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot clone git tree

Tags:

git

linux

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

I cloned the project

git clone https://github.com/cer/event-sourcing-examples

and I tried to switch to that tree but no effect

Would you have any suggestions ?

Best regards

like image 246
Victor Avatar asked Apr 14 '17 12:04

Victor


2 Answers

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:

  • 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.

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

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

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.

like image 95
Dolda2000 Avatar answered Sep 24 '22 10:09

Dolda2000


Check if below things helps.Am using a GIT bash here.

  1. Clone the repository.

    git clone https://github.com/cer/event-sourcing-examples.git

  2. Enter that directory

    cd event-sourcing-examples/

  3. Switch the branch(i am assuming by tree you mean branch)

    git checkout wip-vagrant wip-vagrant is a branch name

  4. To get the update you have to issue a pull command.

    git pull

If you directly want to clone the branch then follow the instructions in above comment(Micheal).

like image 21
ProgrammerBoy Avatar answered Sep 24 '22 10:09

ProgrammerBoy