git 如何从 master 拉取更改并将其合并到当前分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40777853/
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 pull and merge changes into current branch from master?
提问by mukhilsaravanan
I am working on a branch called create
. I have to pull the changes that are made into my branch. I already have done -
我正在一个名为create
. 我必须将所做的更改拉到我的分支中。我已经做了——
git checkout master
git checkout master
git pull origin master
git pull origin master
and now I have to merge it. What's the way to merge it?
现在我必须合并它。有什么方法可以合并?
回答by Naman
Considering that you have updated the master
on your local using
考虑到您已master
使用本地更新
git checkout master && git pull origin master
You can pull the changes to create
branch also using -
您也可以create
使用 -将更改拉到分支
git checkout create && git pull origin master
Edit- As suggested by @Zarwan, rebase is also another option. For details on when to use which, please look into When do you use git rebase instead of git merge?
编辑- 正如@Zarwan 所建议的,rebase 也是另一种选择。有关何时使用 which 的详细信息,请查看何时使用 git rebase 而不是 git merge?
回答by sa77
It is recommended to rebase your feature branch with master rather than merge it. Details below
建议使用 master 重新设置您的功能分支而不是合并它。详情如下
rebase- if you are still working on your feature branch create
, then rebase your feature branch to master
. This allows you to work on your branch with the latest version of master
as if you've just branched off your master.
rebase- 如果您仍在处理您的功能分支create
,则将您的功能分支重新设置为master
. 这允许您使用最新版本在您的分支上工作,master
就像您刚刚从 master 分支上一样。
git checkout create
git rebase master
merge- use it when you finish your task on your feature branch and want to merge it to other branches. For example, when you finish your work on create
branch and want to merge it with master
.
合并- 当您在功能分支上完成任务并希望将其合并到其他分支时使用它。例如,当您在create
分支上完成工作并希望将其与master
.
git checkout master
git merge create
git push origin master
This operation also generates a merge commit on your master
branch.
此操作还会在您的master
分支上生成合并提交。
回答by Zarwan
git checkout create
git checkout create
git rebase origin master
git rebase origin master
This will take the changes on your branch and apply them on top of the current master branch, and your branch will be updated to point to the result. In other words, master
will be merged into create
.
这将在您的分支上进行更改并将它们应用于当前主分支的顶部,并且您的分支将被更新以指向结果。换句话说,master
将被合并到create
.