Git:将Commit提交到不同的分支 [英] Git: Merge a Commit into a different Branch

查看:418
本文介绍了Git:将Commit提交到不同的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有3个分支;




  • 开发 - 我的继续开发分支

  • version_1 - 发布分支

  • version_2 - 发布分支



我必须对 version_2 version_1 / code>和 develop



  git checkout version_1 
git merge&commit commitum>

我认为提交只包含更改,所以只会应用这些更改。但合并冲突是因为它试图更新两个分支之间的所有更改。



是否有合并/移动/仅将小提交中的更改应用于其他分支?

我可以在这些分支上手动重新实现修补程序,但这似乎是一项艰巨的工作,尤其是因为可能需要重新应用更多修补程序,推出到所有其他分行。

 干杯,意志


解决方案

仅合并一个或几个提交意味着使用撤销Git合并?

然后:

  git checkout version_1 
git cherry-pick< commit checksum>

可以应用于多个提交或一系列提交:请参阅


So I have 3 branches;

  • develop - my continued development branch
  • version_1 - a release branch
  • version_2 - a release branch

I had to do a hotfix on version_2 to reship that version, it was a 2 line change in 2 files, very small.

I wanted to apply that fix to version_1 and develop.

So I;

git checkout version_1
git merge <commit checksum>

I thought a commit only contains the changes, so would only apply those. But the merge conflicts because it tries to update all the changes between the two branches.

Is there a way to merge/move/apply ONLY the changes in a small commit to other branches?

I could just manually re-implement the hotfix on those branches, but this seems a lot of hard work, especially as more hotfixes may need to re applied and rolled out to all other branches.

Cheers, Will

解决方案

Merging only one or a few commits mean using git cherry-pick

First cancel the merge you just did: see "Undo a Git merge?".
Then:

git checkout version_1
git cherry-pick <commit checksum>

That can apply to multiple commits or a range of commits: see "How to cherry pick a range of commits and merge into another branch".

这篇关于Git:将Commit提交到不同的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆