git 如何将分支合并到主?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47072807/
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
How to merge branch to master?
提问by k.vincent
I do have a local branch with some changes, and I want to merge it to remote master. When I run: git merge master
I get:
我确实有一个进行了一些更改的本地分支,我想将其合并到远程 master。当我跑步时:git merge master
我得到:
Already up-to-date
已经是最新的
but I still can see that the master doesn't contain the new changes.
但我仍然可以看到 master 不包含新的更改。
I checked the following issue Git merge reports “Already up-to-date” though there is a difference Ask, but it seems in one hand to be outdated, and on the other hand, none of the hints there were helpful.
我检查了以下问题Git 合并报告“已经是最新的”,尽管 Ask 有所不同,但一方面似乎已经过时,另一方面,那里的提示都没有帮助。
Any idea or hint?
任何想法或提示?
回答by divsingh
If you want to merge your branch to master on remote, follow the below steps:
如果要将分支合并到远程 master,请按照以下步骤操作:
- push your branch say 'br-1' to remote using
git push origin br-1
. - switch to master branch on your local repository using
git checkout master
. - update local master with remote master using
git pull origin master
. - merge br-1 into local master using
git merge br-1
. This may give you conflicts which need to be resolved and changes committed before moving further. - Once merge of br-1 to master on local is committed, push local master to remote master using
git push origin master
.
- 使用
git push origin br-1
. - 使用
git checkout master
. - 使用
git pull origin master
. - 使用 将 br-1 合并到本地 master 中
git merge br-1
。这可能会给您带来需要解决的冲突并在进一步移动之前提交更改。 - 一旦将 br-1 合并到本地的 master 提交,使用
git push origin master
.
回答by Navneet
To merge branch with master,there are two ways you can proceed
要将分支与 master 合并,您可以通过两种方式进行
- By Git commands
- By Github Dashboard
- 通过 Git 命令
- 通过 Github 仪表板
Git Commands
Git 命令
Here also you can go with two different commands,first is
在这里你也可以使用两个不同的命令,首先是
- checkout to your master branch using
git checkout master
- pull your latest code from the branch you want to merge,use
git pull --rebase origin branch_name
. It may give you some conflicts which you can resolve by usinggit status
,after resolving you can check if any conflict is more there or not by usinggit --rebase continue
.
- 使用结帐到您的主分支
git checkout master
- 从要合并的分支中提取最新代码,使用
git pull --rebase origin branch_name
. 它可能会给您一些冲突,您可以通过使用来解决这些冲突,解决git status
后您可以通过使用来检查是否存在更多冲突git --rebase continue
。
Second way
第二种方式
- To master you can cherrypick the commits from the branch you want to
merge
git cherry-pick <commit id>
.If you are getting conflict usegit cherry-pick --continue
.
- 要掌握,您可以从要合并的分支中挑选提交
git cherry-pick <commit id>
。如果您遇到冲突,请使用git cherry-pick --continue
。
Actually this is the more suggested way you can proceed.
实际上,这是您可以继续的更建议的方式。
Merge branch using Github Dashboard
使用 Github 仪表板合并分支
This is most easiest way to merge.
这是最简单的合并方式。
Create new pull request, select the branch you want to merge and resolve the conflicts.
创建新的拉取请求,选择要合并的分支并解决冲突。
回答by Bayram Binbir
Merging into master Or another branch:
合并到 master 或另一个分支:
git merge master / or yourBranchName
After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:
合并后,检查是否有冲突。
如果没有冲突,则:
git push
If there is a conflict then fix your file(s), then:
如果存在冲突,则修复您的文件,然后:
git add yourFile(s)
git commit -m 'merging my branch'
git push