Git Merge --no-ff复制提交 [英] Git Merge --no-ff makes copy of commits

查看:259
本文介绍了Git Merge --no-ff复制提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我有一个好奇的git行为,我想问问这是否正常。现在,情况就是这样(新的提交被添加到底部):

  br1 br2 
A
\
B
C
D

现在,当我制作

  git checkout br1 
git merge --no-ff br2

它变成这样(至少git log --graph告诉我什么):

  br1 br2 
A
| \
| B
| C
| D
| /
E

OK ..现在,奇怪的是;现在我称之为git status;它说我在远程分支之前提交了4个。这是怎么发生的?我不应该只是一次提交吗?



特别的是,当我从Stash(Git Web UI,基本上)检查时,它确认了这个4提交状态,我在br1和br2下看到相同的提交(BC和D)...



我在使用--no -ff参数,则br2(BCD)处的提交将不会被复制到br1,并且仅合并提交创建。我错了吗?

解决方案

我认为您误解了分支机构在Git中的工作方式。 分支机构轻巧,这意味着什么在创建新分支或将一个分支合并到另一个分支时被复制。



分支是提交的引用。由于每个提交都与其先前的提交相关联,因此当您指向一个提交时,您实际上是指向该提交的历史记录



你的例子 E 是一个合并提交,它将两个分支结合在一起,创建一个历史记录。这意味着在将 br2 合并为 br1 br1 ( (现在 E 的引用)将知道 br2 的历史因为 D 仍然 D C B E 的历史记录的一部分。



您的本地 br1 是对 E 的引用,而您的远程 br1 仍然是对 A 的引用。因此,有四个提交( B C D E )是 new br1 的历史记录。


I had a curious git behaviour today, and I want to ask if this is normal. Now, this is the situation (new commits are added to the bottom):

br1  br2
  A
    \ 
     B
     C
     D

Now, when I make

git checkout br1
git merge --no-ff br2

It becomes like this (at least what git log --graph tells me):

br1  br2
  A
  | \ 
  |  B
  |  C
  |  D
  | /
  E

OK.. Now, weird thing is; now I call "git status"; it says I'm 4 commits ahead of the remote branch. How is this happening? Shouldn't I be only one commit ahead?

And the peculiar thing is, when I check from the Stash (the Git Web UI, basically) it confirms this "4 commits" status and I see the same commits (B C and D) under "br1" and "br2" both...

I assumed when I used "--no-ff" parameters, the commits at "br2" (B C D) won't be copied to the "br1" and only merge commit created. Am I mistaken here?

解决方案

I think you're misunderstanding how branches work in Git. Branches are lightweight, which means nothing gets copied when you create a new branch or merge one branch into another.

A branch is a reference that points to a commit. Since every commit is linked to its previous commits, when you point to one commit you are effectively pointing to the history of that commit.

In your example, E is a merge commit that combines two branches together, creating a single history. This means that after merging br2 into br1, br1 (which is now a reference to E) will know about the history of br2 (which is still a reference to D), because D, C and B are part of the history of E.

Your local br1 is a reference to E, while your remote br1 is still a reference to A. Therefore, there are four commits (B, C, D and E) that are new to the history of br1.

这篇关于Git Merge --no-ff复制提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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