git 主干修改合并到分支_Git分支用于开发dev,同时将一些更改合并到master中

Previously, using SVN, I would have a branch that was my development branch, which matched the code on the development site. Once in a while, I would make a change in the development branch and then merge just the change into the trunk so I could put it on production. I'm wondering how I might accomplish something similar with git.

Basically, I want to be able merge 1 or a few commits from the branch into the master without merging the entire branch.

Or should I be working with git differently? (I need to release the changes right away so I can't way till all the changes are done.) Should I be working with multiple branches? Can I merge 1 branch into multiple other branches?

解决方案

You've almost answered your question: yes, you can merge one branch into multiple other branches.

So, what you want to do is create a branch just for this feature/bugfix (the common name is "topic"), starting from a common ancestor of all branches you'll want to merge it into. Do your work, commit it, then merge it into all of those.

# say version 1.2.3 is a common ancestor, and it's tagged

git checkout -b bugfix v1.2.3

# do some stuff

git add ...

git commit

git checkout master

git merge bugfix

git checkout dev

git merge bugfix

...

The key part here is to make sure to start your branch at a common ancestor. If you don't, you'll end up merging pieces of other things in as well.

If for some reason it's difficult to find a good common ancestor, you can fall back to cherry-picking. This essentially copies a commit from one place to another. It's best to avoid it when you can, though, since it does mean you end up with two copies of a commit in the history.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值