git - ProGit 书中的箭头方向

标签 git

为什么在 Pro Git book 中显示提交队列的所有图像上箭头指向相反的方向? ********

最佳答案

箭头反射(reflect)了 DAG, Directed Acyclic Graph 之后的方向 在这里代表 Git 中的提交历史(从最近到最旧)。

该表示不是“完美”的,如 Eric Sink details in his article :

One of the coolest things about DAG-based version control tools is that the DAG is an expression of merge history. We interpret arrows in the DAG to mean "'I've got this".

alt text

So, when it comes time to do merge from 5b over to the (a) branch, we can use information in the DAG to know that 3b and 2b are already done


同一篇文章详细说明了该表示的限制:

Cherrypicking

But a DAG is just one implementation of merge history, and it is definitely not perfect.

An arrow in a version control DAG goes from child to parent. It tells us that the child contains all of the changes in the parent. And its grandparents. And its great grandparents. And so on.

But what if this isn't true?

Consider the following picture:

alt text

I want to create changeset 4.
I want to start at changeset 1, and then I want to apply the changes from changeset 3, but NOT the stuff in changeset 2.
This operation is sometimes called "cherrypicking". I don't want to merge all changes from one branch to another. I just want to pluck one changeset (or one part of a changeset) and apply it as a patch to some other place.

How do I represent this in the DAG?

I can't.

  • 我可以画一个从 4 到 3 的箭头(如上图红色所示)。这会正确地说 4 包含 3 中的更改,但它会错误地声称 4 包含 2 中的更改。
  • 或者,我无法绘制箭头。实际上,我的 merge 历史根本不会记录 4 实际上是 3 转换为补丁并应用于 1 的事实。

In either case, something bad is going to happen next time I merge from one branch to the other:

  • If I draw that lying arrow, I will not be given the chance to apply changeset 2, because the merge history believes I already did it.
  • If I don't draw any arrow, the tool will expect me to deal with changeset 3, because there is no merge history recording the fact that I already did it.

Neither of these problems is disastrous enough to make the evening news, but still.

这就是为什么 a rebase is never far经过cherry-pick操作,为了找回更经典的DAG。

关于git - ProGit 书中的箭头方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2676302/

相关文章:

eclipse - 从现有 Git 存储库导入 Gradle 项目

git - 从 webstorm 推送到 Git

git - 在 Git 中找不到远程引用 HEAD

git - blueocean 中的子模块?

git - 推送到远程 :org. ajoberstar.grgit.exception.GrgitException 的问题:

克隆 repo 时的 Gitlab/Gitolite 问题

linux - 使用带有 gnome-keyring 的 Git 凭证助手作为 Sudo 时出错

git - 如何在postgresql中存储类似git分支的数据结构?

git - 使用 gitlab 自定义接收后 Hook

git - 'git ls-remote'命令参数限制返回的行数