Search code examples
gitgit-branchgit-commitgit-clone

checkout to first commit on the branch and clone the repository


I am trying to clone the most recent state (commit), and the initial state of the branch, and compare repositories.

I have cloned the most recent commit.

How can I clone the initial commit of the branch?

56557bc   Project Created New Repo    2019‑04‑09

I have this string here which, I guess, is the commit hash :

https://bitbucket.org/xya/react-native/commits/56557bc9621b7d6e510c51be337fbc5800b65838

Should I git checkout 56557bc9621b7d6e510c51be337fbc5800b65838 and then clone the initial repository?

Does this hamper my recent commits?


Solution

  • I have this string here which, I guess, is the commit hash :

    You don't have to guess: if you see on the Web page for that commit that it has no parent, it is the first commit of the repository (unless it is an orphan branch, but if it is part of master, chances are, it is indeed the one you want)

    am trying to clone the most recent state (commit), and the initial state of the branch, and compare repositories.

    First clone the repo.

    Then use the git worktree command: you will be able to get a second folder, with the commit content you want, without cloning a second time.

    cd /path/to/repo
    git checkout -b first <yourFirstCommit>
    git checkout master
    git worktree add ../first first
    cd ../first