Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cherry-pick to another branch

I wonder if there is the way to copy one commit to another branch without checking out that branch.

For example, I have two branches: master and parallel_version.

I'm on parallel_version branch and I found a bug in file common for these branches.

I've fixed it and committed. How to duplicate this commit to another branch, assuming I'm using git-svn?

Normally I would do:

$ git checkout master $ git cherry-pick parallel_version $ git checkout parallel_version 

Is there better way of doing that?

like image 632
kassak Avatar asked Dec 14 '12 12:12

kassak


People also ask

How do I cherry pick a branch in git?

Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.

How do you cherry pick commits and merge?

With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined. The cherry-pick command allows you to select individual commits for integration.

How do you cherry pick changes from one branch to another in Intellij?

Open the Git tool window Alt+9 and switch to the Log tab. Locate the commit containing the changes you want to cherry pick. on the toolbar). Select the required commit.


2 Answers

That's not possible - simply imagine what would happen if there was a conflict that couldn't be resolved automatically. For the same reason you also can't update branches that are not currently checked-out (even if a fast-forward was possible).

like image 98
ThiefMaster Avatar answered Oct 03 '22 17:10

ThiefMaster


https://github.com/lennartcl/gitl provides "git cherry-copy" and "git cherry-move" scripts that do this and handle most of the corner cases.

like image 37
lennartcl Avatar answered Oct 03 '22 17:10

lennartcl