将 master 合并到分支和将分支合并到 master 之间有什么区别? [英] What is the difference between merging master into branch and merging branch into master?
问题描述
我有一个名为 master
的分支和另一个名为 dev
的分支.通常,我对 dev
进行测试和改进;完成后,我将它合并到 master
中,标记它,然后发布应用程序的新版本.
I have a branch called master
and another called dev
. Usually, I do tests and improvements on dev
; when done, I merge it into master
, tag it, and release new version of the application.
现在,我面临合并的决定:
Now, I face a decision to make in regard to merging:
- 将
master
合并到dev
- 将
dev
合并到master
- merge
master
intodev
- merge
dev
intomaster
但我不太确定两者有什么不同......欢迎任何解释.
but I am not really sure how the two are different... Any explanation would be welcome.
推荐答案
TL;DR
主要区别在于 master
和 dev
分支最终指向的位置.
TL;DR
The main difference lies in where the master
and dev
branches end up pointing.
将一个分支合并到另一个分支不是对称操作:
Merging one branch into another is not a symmetric operation:
- 将
dev
合并到master
和 - 合并
master
到dev
,
- merging
dev
intomaster
, and - merging
master
intodev
,
一般来说,不等价.这是一个说明性示例,解释了两者之间的区别.假设您的存储库如下所示:
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:
如果master
被检出(git checkout master
),
然后你合并dev
(git merge dev
),你会遇到以下情况:
and you then merge dev
(git merge dev
), you will end up in the following situation:
master
分支现在指向新的合并提交(F
),而 dev
仍然指向同一个提交(E
) 与合并前一样.
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.
另一方面,如果 dev
被检出 (git checkout dev
),
If, on the other hand, dev
is checked out (git checkout dev
),
然后你合并master
(git merge master
),你会遇到以下情况:
and you then merge master
(git merge master
), you will end up in the following situation:
dev
分支现在指向新的合并提交(F'
,而 master
仍然指向与之前相同的提交合并 (D
).
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
).
这篇关于将 master 合并到分支和将分支合并到 master 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!