为什么git merge有时会创建一个提交,有时却不会创建一个提交? [英] Why does git merge sometimes create a commit, sometimes does not?

查看:477
本文介绍了为什么git merge有时会创建一个提交,有时却不会创建一个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从另一个分支到当前工作空间执行git merge时,git有时会进行新的提交:

When I do git merge from another branch to current workspace, git sometimes makes a new commit:

Merge remote-tracking branch xxx into xxx

有时候,它不会:

Fast-forward
... src files ...

那是什么决定是否应该创建提交?

So what determines whether a commit should be created or not?

推荐答案

所谓的快速转发"合并不会产生提交,而其他合并(通常称为章鱼合并"(现在您知道为什么) github的吉祥物是octocat))产生提交.

So-called "Fast-forward" merges don't produce a commit, whereas other merges (often refered to as "octopus merge" (now you see why github's mascott is an octocat)) produce commits.

基本上,当您的分支没有分歧时,就会发生快进.

Basically, a Fast-forward happens when your branches did not diverge.

说您要在master分支中合并分支foo.如果这些分支没有分歧,那么您将拥有这样的历史记录(每个*代表一个提交):

Say you want to merge a branch foo in the master branch. If these branches did not diverge, you would have an history like this (each * represents a commit):

*---* (master)
     \
      *---*---* (foo)

在这种情况下,合并是快进,因为(根据图论,这是git图的基础),可以从foo到达master.换句话说,您只需要将master引用移至foo,就可以完成:

In this situation, the merge is fast-forward because (according to the graph theory, which is the underlying foundation of a git graph), master is reachable from foo. In other words, you just have to move the master reference to foo, and you're done:

*---*
     \
      *---*---* (master, foo)

当分支分叉时:

*---*---* (master)
     \
      *---*---* (foo)

您必须创建一个联接"两个分支的提交:

You have to create a commit to "join" the two branches:

                ↓
*---*---*-------* (master)
     \         / 
      *---*---* (foo)

箭头所指的提交是合并提交,并且具有两个父提交(以前的master分支提示和当前的foo分支提示).

The commit pointed by the arrow is the merge commit and has two parent commits (the former master branch tip, and the current foo branch tip).

请注意,您可以使用--no-ff选项强制Git为快速转发合并创建合并提交.

Note that you can force Git to create a merge commit for a fast-forward merge with the --no-ff option.

我强烈建议您阅读 http://think-like-a-git.net/以获得更好的理解图论如何应用于git(您无需了解图论,您需要了解的一切都在网站上),这将使使用Git变得异常容易:)

I highly recommend reading http://think-like-a-git.net/ for a good understanding of how the graph theory applies to git (you don't need to know the graph theory, everything you need to know is on the website), which will make working with Git incredibly easier :)

这篇关于为什么git merge有时会创建一个提交,有时却不会创建一个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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