4

_

I have an project in bitbucket and I want to clone specific commit from it
these are the commits, I want without the last two of them

enter image description here

butin SourceTree I can't see the commits number b6981f9 and 1fb876a
just the last number da84f64 enter image description here

I think because the last 3 pushed together, what I should do?

joda
  • 711
  • 2
  • 8
  • 16
  • Why must it only be a single commit rather than just cloning the whole repository? If this is actually a requirement you should probably explain why. – Chris Oct 02 '16 at 05:42
  • @Chris yes I want the whole repository except the last 2 commits, I don't need it, so how I can specific that cloning? – joda Oct 02 '16 at 06:05

1 Answers1

5

yes I want the whole repository except the last 2 commits, I don't need it, so how I can specific that cloning?

The normal way is to:

  • clone everything
  • checkout a new branch (or reset the current branch) to HEAD~2

    git checkout -b newBranch @~2
    

Other than that:

I have partners in project but we got bug in the last 2 commits

So, with SourceTree:

  • clone the repo (normal clone)
  • select the commit from which you want to work: double-click the commit to check it out, then click 'Branch'.

Once you have created an new branch, work and add new commits, then push your bugfix branch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Actually I'm so beginner with git, so I'm little confused, now do you mean I should clone every thing, and then what I should do delete the last 2 commits from the project? – joda Oct 02 '16 at 06:23
  • Also can I do that by sourceTree? – joda Oct 02 '16 at 06:24
  • @joda not delete, but start working from HEAD~2, in order for your new branch HEAD to start from where you want to. Are you the only one working on that repo? – VonC Oct 02 '16 at 06:24
  • @joda Always start with command-line: much more precise than any GUI. – VonC Oct 02 '16 at 06:25
  • @joda But yes, you can do that from SourceTree as well: https://answers.atlassian.com/questions/54861/how-can-i-create-a-branch-in-sourcetree-git-from-arbitrary-commit – VonC Oct 02 '16 at 06:26
  • Ok, but HEAD~2 means? ist number of commits I don't need it or the name of branch or what? and no I have partners in project but we got bug in the last 2 commits – joda Oct 02 '16 at 06:31
  • @joda `HEAD~2` is a revision selection top reference ancestors: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#Ancestry-References: `HEAD~2` means “the first parent of the first parent,” or “the grandparent” – it traverses the first parents the number of times you specify. . – VonC Oct 02 '16 at 06:36
  • I got that thank you so much, but the problem now the last three commits "da84f64 - 1fb876a - b6981f9" was pushed together like my image in the question، so SourceTree just show me the last one "da84f64" but I need the commit "b6981f9" how I can access to it? – joda Oct 02 '16 at 06:55
  • @joda go to your log view of your cloned repo: https://confluence.atlassian.com/sourcetreekb/viewing-log-history-of-a-repository-785615840.html. You will see all commits there. – VonC Oct 02 '16 at 06:56
  • yes I open it, but I still see the one last commit, it should be the last three like what I see in bitbucket site – joda Oct 02 '16 at 07:10
  • @joda you should see all commits from all branches as shown in https://blog.sourcetreeapp.com/2016/03/01/sourcetree-design-whats-next/. Otherwise, edit your question with a screenshot illustrating the issue. – VonC Oct 02 '16 at 07:12
  • @joda you should still see 1fb and b68 commits below by scrolling done: they have been merged, but are still there in the history. – VonC Oct 02 '16 at 07:34
  • scrolling where? unfortunately the history actually the same branch master – joda Oct 02 '16 at 07:40
  • @joda scrolling *down*: at the right side of your screenshot, there should be a way to scroll down. – VonC Oct 02 '16 at 07:42
  • ohh I see it, now I create branch with it, how I clone it? – joda Oct 02 '16 at 07:49
  • @joda it is already cloned: a cloned Git repo includes the full complete history. Symply create a branch from that commit, as mentioned in https://answers.atlassian.com/questions/54861/how-can-i-create-a-branch-in-sourcetree-git-from-arbitrary-commit – VonC Oct 02 '16 at 08:00
  • The source tree option is handier. Thanks – Tahir Alvi Oct 08 '21 at 14:41