git Git合并两个本地分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25053697/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:17:12  来源:igfitidea点击:

Git merge two local branches

gitmerge

提问by user3127896

I have branch Master, branch A and branch B. Now I'm working in the branch A and I need to merge branch A with branch B and proceed my work in the branch A. All files are comitted in the branch A and B.

我有分支主、分支 A 和分支 B。现在我在分支 A 工作,我需要将分支 A 与分支 B 合并并在分支 A 中继续我的工作。所有文件都在分支 A 和 B 中提交。

What's the fast way to implement it?

实现它的快速方法是什么?

回答by Abimaran Kugathasan

If I understood your question, you want to merge branchBinto branchA. To do so, first checkout branchAlike below,

如果我理解你的问题,你想合并branchBbranchA. 为此,首先branchA像下面这样结帐,

git checkout branchA

Then execute the below command to merge in branchB:

然后执行以下命令合并branchB

git merge branchB

回答by Mahmoud Zalt

Here's a clear picture:

这是一张清晰的图片:

Assuming we have branch-A and branch-B

假设我们有分支 A 和分支 B

We want to merge branch-B into branch-A

我们想将分支 B 合并到分支 A

on branch-B -> A: switch to branch-A

on branch-A: git merge branch-B

回答by user3127896

The answer from the Abiraman was absolutely correct. However, for newbies to git, they might forget to pull the repository. Whenever you want to do a merge from branchB into branchA. First checkout and take pull from branchB (Make sure that, your branch is updated with remote branch)

The answer from the Abiraman was absolutely correct. However, for newbies to git, they might forget to pull the repository. Whenever you want to do a merge from branchB into branchA. First checkout and take pull from branchB (Make sure that, your branch is updated with remote branch)

git checkout branchB
git pull

Now you local branchB is updated with remote branchB Now you can checkout to branchA

Now you local branchB is updated with remote branchB Now you can checkout to branchA

git checkout branchA

Now you are in branchA, then you can merge with branchB using following command

Now you are in branchA, then you can merge with branchB using following command

git merge branchB

回答by Dapo Momodu

on branchB do $git checkout branchAto switch to branch A

on branchB do $git checkout branchAto switch to branch A

on branchA do $git merge branchB

on branchA do $git merge branchB

That's all you need.

That's all you need.

回答by Erdin? ?orbac?

If you or another dev will not work on branchB further, I think it's better to keep commits in order to make reverts without headaches. So ;

If you or another dev will not work on branchB further, I think it's better to keep commits in order to make reverts without headaches. So ;

git checkout branchA
git pull --rebase branchB

It's important that branchB shouldn't be used anymore.

It's important that branchB shouldn't be used anymore.

For more ; https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/

For more ; https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/