git修补分支的子范围的最佳方法是什么? [英] What is the best way to git patch a subrange of a branch?

查看:146
本文介绍了git修补分支的子范围的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Subversion中,使用svn merge -r a:b mybranch很容易合并来自分支的一系列变更集/差异。但在git中,我发现只能从分支中选择一个提交来将该补丁应用于我当前的工作分支。所以我想知道是否有一种快速的方法来将bugfix分支中的两个标签之间的所有提交应用到我当前的主分支?

解决方案

执行您正在查找的操作的最简单方法是使用 git rebase 。这是一个配方。假设标签A是您要选择的补丁系列的顶层提交,并且标签B是系列中最终补丁的提交。另外,假设br是当前分支的名称,以及应该应用新补丁系列的分支。

 #结帐在当前位置的新临时分支
git checkout -b tmp

#将br分支移动到新的补丁集的头部
git分支-f br B

#将补丁集重新加入到tmp中,旧的位置为br
git rebase - tmp A b


In Subversion, it is easy to merge a range of changesets/diffs from a branch using "svn merge -r a:b mybranch". But in git, I found it is only possible to cherry-pick a single commit from a branch to apply that patch to my current working branch. So I am wondering if there is a fast way to apply all the commits in one swoop between two tags in a bugfix branch to my current master branch?

解决方案

The easiest way to perform the action that you are looking for is with git rebase. Here's a recipe. Assume that tag A is the commit on top of which the patch series that you want to select is based and that tag B is the commit of the final patch in the series. Also, assume that br is the name of the current branch and the branch where the new patch series should be applied.

# Checkout a new temporary branch at the current location
git checkout -b tmp

# Move the br branch to the head of the new patchset
git branch -f br B

# Rebase the patchset onto tmp, the old location of br
git rebase --onto tmp A br

这篇关于git修补分支的子范围的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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