[英]Copy changes from one branch to another
I have a branch named BranchA
from master
.我有一个来自master
名为BranchA
的分支。 I have some changes in BranchA
(I am not going to merge changes from BranchA
to master
).我在BranchA
有一些更改(我不打算将BranchA
更改合并到master
)。
Now I have created another branch from master
named BranchB
.现在我从master
创建了另一个名为BranchB
分支。
How can I copy the changes from BranchA
to BranchB
?如何将更改从BranchA
复制到BranchB
?
git checkout BranchB
git merge BranchA
git push origin BranchB
This is all if you intend to not merge your changes back to master.如果您不打算将更改合并回母版,这就是全部。 Generally it is a good practice to merge all your changes back to master, and create new branches off of that.通常,将所有更改合并回 master 并从中创建新分支是一种很好的做法。
Also, after the merge command, you will have some conflicts, which you will have to edit manually and fix.此外,在合并命令之后,您将遇到一些冲突,您必须手动编辑并修复这些冲突。
Make sure you are in the branch where you want to copy all the changes to.确保您位于要将所有更改复制到的分支中。 git merge
will take the branch you specify and merge it with the branch you are currently in. git merge
将采用您指定的分支并将其与您当前所在的分支合并。
Instead of merge, as others suggested, you can rebase one branch onto another:正如其他人建议的那样,您可以将一个分支重新设置为另一个分支,而不是合并:
git checkout BranchB
git rebase BranchA
This takes BranchB
and rebases it onto BranchA
, which effectively looks like BranchB
was branched from BranchA
, not master
.这需要BranchB
并将其BranchA
到BranchA
,这实际上看起来BranchB
是从BranchA
分支的,而不是master
。
This is 2 step process这是 2 步过程
If you want to push your branch code to remote repo then do如果要将分支代码推送到远程仓库,请执行以下操作
Copy content of BranchA into BranchB将BranchA 的内容复制到BranchB
git checkout BranchA
git pull origin BranchB
git push -u origin BranchA
Merge the changes from BranchA to BranchB.合并从 BranchA 到 BranchB 的更改。 When you are on BranchB execute git merge BranchA
当你在 BranchB 时执行git merge BranchA
If you are using tortoise git .如果您使用的是乌龟 git 。
please follow the below steps.请按照以下步骤操作。
BranchB
结账BranchB
TortoiseGit --> Pull
打开项目文件夹,转到TortoiseGit --> Pull
BranchA
and click ok.在拉取屏幕中,更改远程分支BranchA
,然后单击确定。TortoiseGit --> Push
.然后再次右键单击,转到TortoiseGit --> Push
。Now your changes moved from BranchA to BranchB现在您的更改从 BranchA 移至 BranchB
对我来说,解决方案是 - 将当前更改存储在分支中,然后切换分支,然后将该存储应用到该分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.