Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(git): How to bring specific commit from upstream branch?

I have this (git repo):

A--B--C--D ->master
   \--E    ->dev

And I want to bring only commit D to branch dev (D doesn't depend on C), so that:

A--B--C--D  ->master
   \--E--D' ->dev

But D' shouldn't get added to master after a merge:

A--B--C--D--E' ->master
   \--E--D'/   ->dev

This is because I want to bring only a file update without having to pollute dev with new files that C (which represents another, big merge) adds.
I'm guessing I need to use git rebase, but I can't guess how.

like image 726
Steven Arrhenius Avatar asked Feb 16 '10 13:02

Steven Arrhenius


1 Answers

You want to use git cherry-pick. I'll assume your remote is named "origin" (but substitute the real name of the remote repo for "origin"). I'll assume you have two local branches also named master and dev. I'll assume commit D is on origin/dev. You can cherry-pick D with the following:

$ git fetch origin             # Assuming the upstream remote's name is "origin"
$ git checkout dev             # Check out your local "dev" branch
$ git cherry-pick $COMMIT_D    # Replace "COMMIT_D" with the hash for commit D

Now you'll only have the changes from commit D in dev.

like image 96
mipadi Avatar answered Oct 19 '22 14:10

mipadi