views:

71

answers:

3

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.

A: 

StackOverflow destroyed the formatting (yea, next time I'll actually look at the preview):

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

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

A--B--C--D--E' ->master
   \--E--D'/   ->dev
Steven Arrhenius
I have restored the layout within your question. You can delete the "answer"
VonC
A: 

Use git cherry-pick

Arnold Zokas
+3  A: 

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.

mipadi