开发者

(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--开发者_JAVA技巧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.


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.


Use git cherry-pick updated with working link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜