在 Git 中获取从 master 到分支的更改

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

Get changes from master into branch in Git

gitversion-controlgit-merge

提问by Slee

In my repository I have a branch called aqwhich I'm working on.

在我的存储库中,我有一个名为aq我正在处理的分支。

I then committed new work and bugs in master.

然后我在master.

What is the best way to get those commits into the aqbranch? Create another new branch out of masterand merge it with aq?

将这些提交放入aq分支的最佳方法是什么?创建另一个新分支master并将其与aq?

回答by Douglas F Shearer

Check out the aqbranch, and rebase from master.

检查aq分支,并从master.

git checkout aq
git rebase master

回答by Chris Kooken

You should be able to just git merge origin/masterwhen you are on your aq branch.

git merge origin/master当你在你的 aq 分支时,你应该能够。

git checkout aq
git merge origin/master

回答by Hrishikesh Mishra

First check out to master:

先签出高手:

git checkout master

Do all changes, hotfix and commits and push your master.

进行所有更改、修补程序和提交,然后推送您的主人。

Go back to your branch, 'aq', and merge master in it:

回到你的分支,'aq',并在其中合并 master:

git checkout aq
git merge master

Your branch will be up-to-date with master. A good and basic example of merge is 3.2 Git Branching - Basic Branching and Merging.

您的分支将与 master 保持同步。合并的一个很好的基本示例是3.2 Git Branching - Basic Branching and Merging

回答by Adam Dymitruk

There is no guarantee that the master bug fixes are not amongst other commits, hence you can't simply merge. Do

不能保证主错误修复不在其他提交中,因此您不能简单地合并。做

git checkout aq
git cherry-pick commit1
git cherry-pick commit2
git cherry-pick commit3
...

assuming those commits represent the bug fixes.

假设这些提交代表错误修复。

From now on though, keep bug fixes in a separate branch. You will be able to just

不过从现在开始,将错误修复保留在单独的分支中。你将能够只

git merge hotfixes

when you want to roll them all into the regular dev branch.

当您想将它们全部滚动到常规开发分支时。

回答by Alan Haggai Alavi

Either cherry-pickthe relevant commits into branch aqor merge branch masterinto branch aq.

无论是cherry-pick有关提交到分支aq或合并分支master到分支aq

回答by alditis

Merge it with aq

合并它 aq

git checkout master
git pull
git checkout aq
git merge --no-ff master
git push

回答by Alen Lee

Easy way

简单的方法

# 1. Create a new remote branch A base on last master
# 2. Checkout A
# 3. Merge aq to A

回答by Pete B.

For me, I had changes already in place and I wanted the latest from the base branch. I was unable to do rebase, and cherry-pickwould have taken forever, so I did the following:

对我来说,我已经进行了更改,我想要来自基础分支的最新版本。我无法做到rebase,并且cherry-pick会永远花费,所以我做了以下事情:

git fetch origin <base branch name>  
git merge FETCH_HEAD

so in this case:

所以在这种情况下:

git fetch origin master  
git merge FETCH_HEAD

回答by estellezg

This (from here) worked for me:

这(从这里)对我有用:

git checkout aq
git pull origin master
...
git push

Quoting:

引用:

git pull origin masterfetches and merges the contents of the master branch with your branch and creates a merge commit. If there are any merge conflictsyou'll be notified at this stage and you must resolve the merge commits before proceeding. When you are ready to push your local commits, including your new merge commit, to the remote server, run git push.

git pull origin master获取 master 分支的内容并将其与您的分支合并,并创建一个合并提交。如果有任何合并冲突,您将在此阶段收到通知,并且您必须在继续之前解决合并提交。当您准备好将本地提交(包括新的合并提交)推送到远程服务器时,运行git push.

回答by Dan McNamara

You have a couple options. git rebase master aqonto the branch which will keep the commit names, but DO NOT REBASE if this is a remote branch. You can git merge master aqif you don't care about keeping the commit names. If you want to keep the commit names and it is a remote branch git cherry-pick <commit hash>the commits onto your branch.

你有几个选择。git rebase master aq到将保留提交名称的分支上,但如果这是远程分支,请不要重新定位。你可以git merge master aq,如果你不关心保持提交的名称。如果您想保留提交名称并且它是远程分支,git cherry-pick <commit hash>则提交到您的分支。