git 如何从主分支获取更改到本地分支?

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

How to get changes from master branch to local branch?

gitgit-merge

提问by rigby

I have, what I assume, is a typical workflow.

我有,我假设,是一个典型的工作流程。

Our project works with pull requests.

我们的项目适用于拉取请求。

To develop new feature I create a dev. branch. By the time I am finished with the feature some changes were made in master so I want to get those changes into my branch so I make pull request.

为了开发新功能,我创建了一个开发人员。分支。当我完成该功能时,在 master 中进行了一些更改,因此我想将这些更改放入我的分支中,因此我提出了拉取请求。

From what I've read on the internet there are two options for that:

根据我在互联网上阅读的内容,有两种选择:

  1. merge
  2. rebase
  1. 合并
  2. 变基

However, I tried both of them but when I make pull request it shows that all files were changed in this pr.

但是,我尝试了它们,但是当我发出拉取请求时,它显示此 pr 中的所有文件都已更改。

Here is what I did:

这是我所做的:

on the branch

在树枝上

-- git commit -a -m "changes i made on my branch" 
-- git checkout master
-- git fetch upstream
-- git merge upstream/master
-- git checkout mybranch
-- git merge master (or rebase)
-- git push origin mybranch

result -- merge commit in the history shows files changes: 90

结果 - 历史记录中的合并提交显示文件更改:90

What is the correct way to get updates from master into my branch?

从 master 获取更新到我的分支的正确方法是什么?

Similar situation happens when somebody reviews my pr and I need to update my pr. Once again, I end up needing the changes from master.

当有人查看我的 pr 并且我需要更新我的 pr 时,也会发生类似的情况。再一次,我最终需要来自 master 的更改。

Thanks for the help.

谢谢您的帮助。

回答by Matteo Gaggiano

You can pull changes from master to your branch with:

您可以使用以下命令将更改从 master 拉到您的分支:

git checkout my_branch    # move on your branch (make sure it exists)
git fetch origin          #?fetch all changes
git pull origin master    # pull changes from the origin remote, master branch and merge them into my_branch
git push origin my_branch # push my_branch

回答by Rohit shah

-- git checkout mybranch

-- git merge master (or rebase)

-- git checkout mybranch

-- git merge master (或rebase)

Till this it is correct

直到这是正确的

After this you are directly pushing to your branch, before this just add and commit like this.

在此之后,您直接推送到您的分支,在此之前只需像这样添加和提交。

-- git add .

-- git commit -m "msg after merging"

-- git push origin mybranch

- git 添加。

-- git commit -m "合并后的味精"

-- git push origin mybranch

This will merge Master Branch Code with your branch (i.e. mybranch) & will push the code to origin

这会将主分支代码与您的分支(即 mybranch)合并,并将代码推送到原点