1

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?

Azima
  • 3,835
  • 15
  • 49
  • 95
  • 1
    You typically don't clone commits, you clone entire _repositories_. Please include the Git commands you have already tried, which led up to your question. – Tim Biegeleisen Jul 10 '19 at 04:26
  • @TimBiegeleisen yes.. I meant the same.. clone the entire "initial" repository. But I don't know how to. – Azima Jul 10 '19 at 04:27

2 Answers2

3

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `git worktree add ../first first` gives `fatal: 'first' is already checked out at 'C:/xampp/htdocs/repo'` – Azima Jul 10 '19 at 04:54
  • @Azima Yes, I missed an intermediate checkout: see my edited answer. – VonC Jul 10 '19 at 04:55
1

First check out your log by git log.

Then take the Hash code of your targeted commit.

Then git checkout <commit hash>

ChrisM
  • 505
  • 6
  • 18
Shahadat Hossain
  • 533
  • 7
  • 20
  • 1
    When someone clone a project from the git then the person clone the whole project. After clone the whole project you may able to check others commits, branches and a lot of things. **Now come to the point:** **Read carefully:** Before doing any `checkout` first check the **status** by `git status` then add to store in the local by `git add .` after that make a simple commit `git commit -m "Your comment about commit"` Now again check the status by `git status`. If shown nothing to commit shows and working directory shows clean then you can do the further job without risk – Shahadat Hossain Jul 10 '19 at 05:02
  • 1
    If any problem occurs in the future then you will be able to back to the recent commit that you make now. So feel free to `commit` first before doing any changes, `checkout` or this kind of job. **Another thing**, No need to worry about Hash String. Just check log `git log'. You will find out your hash string. – Shahadat Hossain Jul 10 '19 at 05:08