合并提交有什么问题? [英] What is wrong with merge commits?

查看:124
本文介绍了合并提交有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多问题,人们在问如何避免毫无意义的合并提交。



合并提交有什么不好?我发现它们很有用,因为您可以清楚地看到两个开发人员开始工作的位置,以及将工作合并到一起的位置。看起来好像重新定义,因为很多答案都表明这样做,破坏了这些信息,并且你失去了很多项目的历史。



合并提交不合需要?

解决方案

有两种不同类型的合并提交:


  • 显式合并提交,例如将明确合并到主分支

  • 和隐式合并提交(例如,通过执行一个 git pull 在尝试推送之前



显式合并提交通常是完美的精细。你通常甚至通过说 git merge --no-ff 来执行这些合并提交。



就像典型的情况一样,一个开发人员改变了一个文件,然后另一个开发人员在另一个文件上工作,但在做这些改动之前忘了拉,而且 git pull 将通过创建噪声合并提交隐式合并两个提交。更合乎逻辑的历史将是一个作者的一个提交和另一个作者的一个提交。做 git pull --rebase 就是这样。



当然也有例外。如果两位作者实际上都在处理同一个文件,那么在这一点上进行合并提交可能会更好。 - 但即使在这种情况下,也许rebase可能会更好,因为它会使第一次提交的更改更加明确,因此不易出错。


I see a lot of questions where people are asking how that can avoid "pointless" merge commits.

What exactly is bad about a merge commit? I find them useful, as you can see exactly where two developers started working, and where there work is merged together. It seems like rebasing, as a lot of answers suggest doing, destroys this information and you lose a lot of the project's history.

Is there something I am missing that makes a merge commit undesirable?

解决方案

There are two different kind of merge commits:

  • Explicit merge commits, which result for example from explicitly merging a feature branch into the main branch
  • and implicit merge commits, which result for example by doing a git pull before trying to push

The explicit merge commits are usually perfectly fine. You usually even enforce those kind of merge commits by saying git merge --no-ff.

The implicit ones tent to be just noise, as the typical situation is, that one developer changed one file and afterwards another developer works on another file but forgot to pull before doing the changes, and a git pull will implicitly merge both commits by creating a noisy merge commit. The more logical history would be simply one commit from the one author and one commit from the other author. Doing git pull --rebase will exactly do that.

Of course there are exceptions. If both authors actually worked on the same file, it might be better to have a merge commit at this point. - But even in this case maybe a rebase might be better, as it makes the changes against the first commit more explicit and therefore less error-prone.

这篇关于合并提交有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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