Git操作咨询:如何将master分支的Bug修复同步到开发分支?
Git分支Bug修复同步方案
直接合并master到development(可行,适合特定场景)
如果master分支除了你这次的Bug修复没有其他无关提交,直接合并是最简单的方式:
- 切换到development分支:
git checkout development - 拉取远程最新的master代码(确保本地master是最新状态):
git pull origin master - 执行合并:
git merge master - 若出现冲突,手动解决冲突后,执行:
git add .,git commit -m "Merge master bug fix into development" - 推送到远程development分支:
git push origin development
用cherry-pick精准同步Bug修复提交(更灵活)
如果master分支还有其他你不需要的更新,推荐用cherry-pick只同步Bug修复的提交:
- 切换到master分支,查看提交日志找到Bug修复的commit哈希:
git log --oneline(复制类似a1b2c3的短哈希) - 切回development分支:
git checkout development - 执行cherry-pick:
git cherry-pick a1b2c3 - 若遇冲突,解决后执行:
git add .,git cherry-pick --continue - 推送结果到远程:
git push origin development
总结:直接合并master到development是可行的,但如果master有其他无关更新,cherry-pick能避免引入多余代码,更精准。
内容的提问来源于stack exchange,提问作者Lee Casey
相关产品推荐
相关产品推荐

