Git 将更改从一个分支复制到另一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40975751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git copy changes from one branch to another
提问by Mukil Deepthi
I am new to git. I have a branch named BranchAfrom the master. I have some changes in BranchA(I am not going to merge changes from BranchAto master) Now I have created another branch from the master named BranchB. I want the changes from BranchAto BranchB.
我是 git 新手。我有一个来自 master的分支,名为BranchA。我在BranchA 中有一些更改(我不打算将BranchA 的更改合并到 master) 现在我从 master 创建了另一个名为 BranchB 的分支。我想要从BranchA到 BranchB的更改。
Can anyone help me how to achieve this?
谁能帮助我如何实现这一目标?
Thanks
谢谢
回答by roymustang86
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
将采用您指定的分支并将其与您当前所在的分支合并。
回答by Archie
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
,它实际上看起来像是BranchB
从BranchA
,而不是从 分支出来的master
。
回答by TULSI JAIN
This is 2 step process
这是 2 步过程
- git checkout BranchB( destination branch is BranchB, so we need the head on this branch)
- git merge BranchA(it will merge BranchB with BranchA. Here you have merged code in branch B)
- git checkout BranchB(目标分支是BranchB,所以我们需要这个分支上的head)
- git merge BranchA(它会将 BranchB 与 BranchA 合并。这里你已经合并了分支 B 中的代码)
If you want to push your branch code to remote repo then do
如果要将分支代码推送到远程仓库,请执行以下操作
- git push origin master(it will push your BranchB code to remote repo)
- git push origin master(它会将你的 BranchB 代码推送到远程仓库)
回答by Pankaj Singh
Copy content of BranchAinto BranchB
将BranchA 的内容复制到BranchB
git checkout BranchA
git pull origin BranchB
git push -u origin BranchA
回答by C1sc0
Merge the changes from BranchA to BranchB. When you are on BranchB execute git merge BranchA
合并从 BranchA 到 BranchB 的更改。当您在 BranchB 时执行git merge BranchA
回答by Shakthifuture
If your using tortoise git.
如果您使用乌龟 git。
please follow the below steps.
请按照以下步骤操作。
- Checkout BranchB
- Open project folder, go to TortoiseGit --> Pull
- In pull screen, Change the remote branch "BranchA" and click ok.
- Then right click again, go to TortoiseGit --> Push.
- 结账分行B
- 打开项目文件夹,转到 TortoiseGit --> Pull
- 在拉屏中,更改远程分支“BranchA”并单击确定。
- 然后再次右键单击,转到 TortoiseGit --> Push。
Now your changes moved from BranchA to BranchB
现在您的更改从 BranchA 移至 BranchB