Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 337
Farrukh Chishti Avatar asked Apr 01 '15 14:04

Farrukh Chishti


People also ask

Does git cherry pick rewrite history?

The git cherry-pick is a very useful command. It takes changes from a specific commit and applies them to your current branch in a new commit. As a consequence, git cherry pick does not alter your current Git history : instead it adds commits to it.

How do you cherry pick a commit from another branch in command line?

Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.

How do you cherry pick a commit from another branch using TortoiseGit?

Cherry-picking in TortoiseGit is invoked from the Revision Log Dialog. Within this dialog, select the commit(s) to cherry-pick, then right-click on one of the selected commits to pop up the context menu. Select Cherry Pick this commit... (or Cherry Pick select commits... if more than one commit is selected).


2 Answers

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

like image 68
Daniel Sokolowski Avatar answered Oct 31 '22 04:10

Daniel Sokolowski


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.

like image 24
Ben Siver Avatar answered Oct 31 '22 03:10

Ben Siver