将master合并到分支和将分支合并到master中有什么区别? [英] What is the difference between merging master into branch and merging branch into master?

查看:1132
本文介绍了将master合并到分支和将分支合并到master中有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 master 的分支,另一个名为 dev 。通常,我会在 dev 上进行测试和改进,如果确定它是正确的,我将它合并到 master 中,然后标记并发布新版本的应用程序。我遇到了两种合并案例:


  1. 合并 master dev

  2. 合并 dev master

但我不确定这两者是如何不同的......任何解释都会受到欢迎。

解决方案

TL; DR



主要区别在于 master dev 分支最终指向。



完整解释



合并一个分支到另一个分支不是一个对称操作:


  • 合并 dev 转换为 master

  • 合并 master 转换为 dev



,不等同。这里是解释两者之间差异的说明性示例。假设您的回购看起来如下所示:



dev 合并到 master 中,

如果检出 master git checkout master ),





然后你合并 dev git merge dev ),你最终会出现以下情况:



$ b $ master 分支现在指向新的合并提交( F ),而 dev 仍然指向相同的提交( E )如果您将 master 合并到 dev中,则 / h2>

另一方面,如果签出 dev git checkout dev ),




然后合并 master git merge master ),您将在以下情况下结束:



$ b $ dev 分支现在指向新的合并提交( F',而 master 仍然指向与合并前相同的提交( D )。



把它放在一起




I have a branch called master and another called dev. Usually, I do tests and improvements on dev, and when decided it is OK, I merge it into master, then tagging and release new version of the application. I met two cases of merging:

  1. merge master into dev, and
  2. merge dev into master,

but I am not really sure how the two are different... Any explanation would be welcome.

解决方案

TL;DR

The main difference lies in where the master and dev branches end up pointing.

Full explanation

Merging one branch into another is not a symmetric operation:

  • merging dev into master, and
  • merging master into dev,

are, in general, not equivalent. Here is an illustrative example that explains the difference between the two. Let's assume your repo looks as follows:

If you merge dev into master

If master is checked out (git checkout master),

and you then merge dev (git merge dev), you will end up in the following situation:

The master branch now points to the new merge commit (F), whereas dev still points to the same commit (E) as it did before the merge.

If you merge master into dev

If, on the other hand, dev is checked out (git checkout dev),

and you then merge master (git merge master), you will end up in the following situation:

The dev branch now points to the new merge commit (F', whereas master still points to the same commit as it did before the merge (D).

Putting it all together

这篇关于将master合并到分支和将分支合并到master中有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆