开发者

"Complicated" merge scenario in Git

I've been asked if the following is possible in Git, and it's beyond my knowledge:

Given the following scenario:

  • I make a new branch "cool-feature" from trunk and do some work in it
  • I make another branch "fancy-enhancement" from "cool-feature" and do some work in it

Is it possible that I can get the diff between cool-feature and fancy-enhancement and commit only that to trunk? So any stuff added for cool-feature is left behind?

MASTER
   \
    cool-feature
     \
     fancy开发者_如何转开发-enhancement

It makes sense to me that this should be possible, but I'm not sure how I would get the diff between the two branches.


Use "git diff branch1..branch2" then merge the diff it spits out, or better "git log branch1..branch2" then cherry-pick the commits you need.

I think the best option though, especially if you've got a lot of commits, is to use an interactive rebase. The diff and log methods I'd only use if I had a few commits or less (actually I wouldn't use the diff method at all because you'd lose your log messages).

Just make sure you do all this on a new branch rather than directly on master, so you can roll back if it breaks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜