How to cherry pick from branch A to branch B on a system without history?
Asked Answered
H

6

16

Suppose I have a new system with no git history and I take a fresh checkout of branch A. Branch A already has a commit C1 which I did yesterday from some other system. Now I want to cherry-pick this commit C1 in branch B. Issue:

  1. If I take checkout of branch A and go to commit C1 (in history in Git view) and click 'cherry pick', it says do you want to cherry pick in branch A? So, there is no discussion of branch B here.
  2. If I take checkout of branch B it will not show commit C1 at all.

Now, how do I cherry pick commit C1 of branch A into branch B? I am using Gerrit, GitBlit and EGit in eclipse.

Hochstetler answered 1/4, 2015 at 14:45 Comment(0)
L
12

I'm not familiar with the GUI you are using in particular, but the concept you are describing is perfectly acceptable in git.

To cherry-pick a commit from branch A to branch B, use the following command line commands:

git checkout branchB
git cherry-pick hashOfC1

There should be a sort of 'view all branches' mode in the GUI you are using so that you can see commit C1 while having branch B checked out, but if not, the above commands are simple enough to execute.

Linc answered 1/4, 2015 at 14:51 Comment(3)
I guess there commands are for git bash. Can I do this using egit from eclipse?Hochstetler
The EGit user guide has a really good example on how to cherry-pick from their UI.Linc
GOT IT !!! The culprit was a small cylinder in upper right corner of history view saying "Show all changes in repository containing the selected resource". That needs to be selected to show commits of all branches. However, this leaves an open question. When I checkout branch B does it pull all the details of all the branches to update this history tree?Hochstetler
H
16

Qualatar comment is a little outdated, here is how to show all branches in 'Show History' in 'Version: Luna SR2 (4.4.2)' so that you can 'right click > Cherry Pick'.

how to see all commits in Eclipse IDE EGIT to cherry pick

Hedi answered 30/7, 2015 at 17:0 Comment(0)
L
12

I'm not familiar with the GUI you are using in particular, but the concept you are describing is perfectly acceptable in git.

To cherry-pick a commit from branch A to branch B, use the following command line commands:

git checkout branchB
git cherry-pick hashOfC1

There should be a sort of 'view all branches' mode in the GUI you are using so that you can see commit C1 while having branch B checked out, but if not, the above commands are simple enough to execute.

Linc answered 1/4, 2015 at 14:51 Comment(3)
I guess there commands are for git bash. Can I do this using egit from eclipse?Hochstetler
The EGit user guide has a really good example on how to cherry-pick from their UI.Linc
GOT IT !!! The culprit was a small cylinder in upper right corner of history view saying "Show all changes in repository containing the selected resource". That needs to be selected to show commits of all branches. However, this leaves an open question. When I checkout branch B does it pull all the details of all the branches to update this history tree?Hochstetler
C
12

goto "Team Synchronizing", right click on project to display the menu. select show In -> History. This will display History tab with changesets.

enter image description here history tool bar

when you click on icon with 2 arrows downwards then you will see all the changes even those not from your branch. Right click on changeset that you want to cherry pick and then select Cherry Pick.. option as shown in the picture

enter image description here

Costanzia answered 30/6, 2016 at 21:3 Comment(0)
V
3

Step : Pick From other Branch

Switch your current branch

enter image description here

  1. Click / Tick / Show all Branch
  2. Select and right click -> cherry pick the commit

enter image description here

  1. continue until finish.
  2. Right click project and push commit on current branch.
Varicotomy answered 13/7, 2018 at 9:56 Comment(0)
B
3

To Cherry pick onto another branch in Eclipse eGit follow these steps:

  1. Checkout a branch where you would to do cherry pick a commit to.
  2. Open History View.
  3. In the toolbar click on "Change which commits to show" to show All branches matching the configured ref filters.
  4. Select a commit and open context menu and press Cherry pick.
Bust answered 26/12, 2020 at 9:35 Comment(0)
L
2

If you are using Eclipse or STS,

  • Navigate to Windows -> Show View -> History to open the
    history view.
  • Select the branch icon (below image) on the right top of the history view to see commits from all the branches enter image description here
  • Navigate to the commit Id you are interested in, right click and
    select Cherry-Pick
Lannylanolin answered 1/7, 2022 at 6:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.