如何git cherrypick特定分支中引入的所有更改 [英] How to git cherrypick all changes introduced in specific branch

查看:324
本文介绍了如何git cherrypick特定分支中引入的所有更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景信息:

由于在现有系统上工作流程的限制,我们需要建立一个有点非常规的git流程.

Due to restrictions in workflow with out existing systems, we need to set up a somewhat unorthodox git process.

(patch)    A-B---F
             |   |
(hotfix)     C-D-E
                 |
(dev)      1-2-3-G

在补丁分支上,有一些提交.此处的文件相似,但与dev上的文件不同(同步脚本会在许多文件中切换设置的顺序,从而使它们在功能相同时看起来有所更改).

On the patch branch, there are some commits. The files here are similar but not identical to the ones on dev (sync scripts switch around the order of settings in many of the files, making them appear changed while they are functionally the same).

此分支需要修复,因此将创建并处理一个修补程序分支.到目前为止,该分支已合并回补丁中.

A fix is needed on this branch so a hotfix branch is created and worked on. This branch is then merged back into patch, so far, so good.

此修补程序需要部署到dev分支,因此它与补丁保持相对同步,但是尝试合并此修补程序分支会导致git尝试合并A和B中所有不相关且未更改的文件,而不只是C,D和E.

This same fix needs to be deployed to the dev branch so it stays relatively in sync with patch, but trying to merge the hotfix branch leads to git trying to merge all the unrelated and 'unchanged' files from A and B as well, rather than only C,D and E.

问题:

看来,Cherry-pick仅从选定的提交中获取更改就可以完成我们想要的工作,但是我真的很想一种方法,可以一次在指定分支中一次性选择所有提交,而不必查找提交.每次都有ID.

It seems that cherry-pick does what we want in terms of only getting changes from selected commits, but I would really like a way to cherry-pick all commits in a given branch at once, without having to look up the commit ids every time.

推荐答案

似乎cherry-pick仅从选定的提交中获取更改即可完成我们想要的工作,但是我真的很想一种方法,一次在指定的分支中挑选所有提交,而不必查找提交每次都输入ID.

It seems that cherry-pick does what we want in terms of only getting changes from selected commits, but I would really like a way to cherry-pick all commits in a given branch at once, without having to look up the commit ids every time.


使用cherry-pick

git cherry-pick允许您选择在任何分支中对任何其他分支所做的所有提交.在您的情况下,您可以简单地检出master分支,然后cherry-pick任意分支中的所有提交(cherry-pick支持范围,因此您可以指定开始和结束提交,而不列出所有提交).


Using cherry-pick

git cherry-pick allows you to pick any commits you made in any branch to any other branch. In your case you can simply checkout master branch and then cherry-pick all the commits from any branch that you wish (cherry-pick supports ranges so you can specify start and end commit instead of listing all the commits).

通过这种方式,您可以控制提交在所需分支中的显示方式.

This way you can control the way your commits will appear in the desired branch.

例如:

git cherry-pick ebe6942..905e279


# Find the range of commits you wish to re-add to your branch.
# then use cherry-pick to add them back to the branch
git cherry-pick start..end

# If you wish to include the start commit as well add the ^
# This will result in a cherry-pick of the start commit included as well 
git cherry-pick start^..end


如何查找分支的第一次提交?

git log


How to find first commit of branch?

git log

 # print out the latest commit (first one) of the given branch
 git log  --oneline | tail -1

merge-base

使用merge-base命令查找分支与原始分支的分割位置:

merge-base

Use the merge-base command to find where the branch was split from the original branch:

git merge-base A B

这篇关于如何git cherrypick特定分支中引入的所有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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