git 将 master 合并到 dev 分支的正确方法

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

Right way to merge master into dev branch

git

提问by user2094178

When I have ongoing changes at devbranch, and something breaks in production environment, then I switch to master, fix the problem and synchronize the production environment with the masterbranch.

当我在dev分支进行持续更改,并且生产环境出现问题时,我会切换到master,修复问题并将生产环境与master分支同步。

Now I return to devbranch. This branch is synchronized with testand stagingenvironment.

现在我回到dev分支。该分支teststaging环境同步。

What is the proper way to bring to dev branch that fix from master?

将 master 修复的 dev 分支带到 dev 分支的正确方法是什么?

Currently I do git merge masterwhen at devbranch.

目前我git merge masterdev分支机构时这样做。

But when merging like that, I noticed a new commit is created staging the modified files from master.

但是当像这样合并时,我注意到一个新的提交被创建,从master.

I was under the impression when merging that the commits created at master when applying the fix would just be inserted into the dev branch.

在合并应用修复程序时在 master 上创建的提交时,我的印象是只会插入到 dev 分支中。

回答by Makoto

Provided that your staging environment is clean (as in, you don't have any uncommitted or unstashed changes on your development branch)...

假设您的暂存环境是干净的(例如,您的开发分支上没有任何未提交或未隐藏的更改)...

git merge master

...is the idiomatic* way to merge changes from your master branch in.

...是从主分支合并更改的惯用*方式。

When you merge, you bring in all of the changes which are at the tip of that branch, so you'll be bringing in all of the changes from master at once, and you'll have to deal with merge conflicts if they exist. If you can't fast-forward the changes over from master to dev, then you'll also get a merge commit.

当您合并时,您会引入该分支尖端的所有更改,因此您将同时引入来自 master 的所有更改,并且您必须处理合并冲突(如果它们存在)。如果您不能将更改从 master 快进到 dev,那么您还将获得合并提交。

The reason that you may see a lot of commits may be due to the fact that you can't fast-forward your dev branch to line up with master. This shouldn't put you off; simply commit and push those changes into your dev branch as well.

您可能会看到大量提交的原因可能是因为您无法快进您的 dev 分支以与 master 对齐。这不应该让你失望;只需提交并将这些更改推送到您的开发分支中。

*: You can also do git rebase masterwhile on dev, but this has a much higher risk since you're rewriting history. Makes for a cleaner history, though.

*:您也可以git rebase master在 上执行while dev,但由于您正在重写历史,因此风险要高得多。不过,这让历史更清晰。