[英]How to take changes from one remote branch to other remote branch
I'm working on a project and I cut a branch from a release_branch let's call my branch branch_A .我正在做一个项目,我从release_branch中剪下一个分支,让我们称我的分支为 branch_A 。 My colleague also had cut another branch from same release branch and lets call that branch_B .我的同事还从同一个发布分支中删除了另一个分支,我们称之为branch_B 。 We are working on the same file and section hence to avoid any merge conflicts I wanted to take changes from branch_B to my branch_A .我们正在处理相同的文件和部分,因此为了避免任何合并冲突,我想将更改从branch_B更改为我的branch_A 。 Changes of branch_B has already been merged into that release_branch from which we had cut our branches earlier. branch_B的更改已经合并到我们之前从中删除分支的release_branch中。
Can somebody tell what should I do?有人可以告诉我该怎么办吗? I've tried pull but it didn't work.我试过拉,但没有用。 Also I switched to the release_branch and took pull and changes were there but as soon as I switched to my branch_A the changes were gone.我也切换到release_branch并进行了拉取,并且那里有更改但是一旦我切换到我的branch_A更改就消失了。 Please help.请帮忙。
First, make sure that you commit all changes to your branch_A
and if you are concerned about losing your work as part of the process, create a new branch at branch_A
(eg branch_A_old
).首先,确保您将所有更改提交到您的branch_A
并且如果您担心在此过程中丢失您的工作,请在branch_A
创建一个新分支(例如branch_A_old
)。
Since you will eventually be merging back to release_branch
, you can use one of the following approaches:由于您最终将合并回release_branch
,因此您可以使用以下方法之一:
branch_A
, if not already, then pull from remote_name/release_branch
into branch_A
using git pull --no-rebase remote_name/release_branch
.检查branch_A
,如果尚未检查,则使用git pull --no-rebase remote_name/release_branch
从remote_name/release_branch
拉入branch_A
。 This will create a merge commit, merging the latest release_branch
, including changes made by branch_B
into your branch.这将创建一个合并提交,合并最新的release_branch
,包括branch_B
所做的更改到您的分支中。 If there are any conflicts, you will have to resolve them and perform a commit to complete the merge.如果有任何冲突,您将必须解决它们并执行提交以完成合并。branch_A
, fetch remote_name/release_branch
, then merge remote_name/release_branch
into branch_A
.签branch_A
,获取remote_name/release_branch
,然后将remote_name/release_branch
合并到branch_A
中。 This is basically the same as method 1, but broken into two steps.这与方法 1 基本相同,但分为两个步骤。branch_A
, fetch remote_name/release_branch
, then rebase branch_A
using remote_name/release_branch
as the upstream branch.签branch_A
,获取remote_name/release_branch
,然后使用branch_A
remote_name/release_branch
作为上游分支对 branch_A 进行变基。 Alternatively, you can use use git pull --rebase remote_name/release_branch
to combine the fetch and rebase into one step.或者,您可以使用 use git pull --rebase remote_name/release_branch
将获取和变基合并为一个步骤。 Methods 1 and 2 will keep the merge as part of the history and method 3 will update all of the commits in your branch so that your branch begins at the latest commit of release_branch
.方法 1 和 2 会将合并保留为历史的一部分,方法 3 将更新分支中的所有提交,以便您的分支从release_branch
的最新提交开始。
Methods 1 and 2 are usually easier, although this is debatable, but method 3 will provide a cleaner history.方法 1 和 2 通常更容易,尽管这是有争议的,但方法 3 将提供更清晰的历史记录。 If you do use method 1 or 2, you can always perform a squash later to clean up the history.如果您确实使用了方法 1 或 2,您以后总是可以执行压缩以清理历史记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.