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

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

问题描述

所以我有 3 个分支;

So I have 3 branches;

  • develop - 我的持续开发分支
  • version_1 - 一个发布分支
  • version_2 - 一个发布分支
  • develop - my continued development branch
  • version_1 - a release branch
  • version_2 - a release branch

我不得不在 version_2 上做一个修补程序来重新发布那个版本,这是在 2 个文件中的 2 行更改,非常小.

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

我想将该修复应用到 version_1develop.

I wanted to apply that fix to version_1 and develop.

所以我;

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

推荐答案

仅合并一个或几个提交意味着使用 git cherry-pick

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

首先取消您刚刚执行的合并:请参阅撤消 Git 合并?".
然后:

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:将提交合并到不同的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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