为什么--first-parent不是git show的默认显示? [英] Why is --first-parent not the default for git show?

查看:120
本文介绍了为什么--first-parent不是git show的默认显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这个问题将以基于观点的观点解决,但是没有别的地方可以提出来,所以就去吧...

I'm sure this question will be closed as opinion-based but there's nowhere else so ask it so here goes...

我正在尝试查看分支的历史记录,其中包括合并提交(特别是更改的内容),并且在这里找到了非常有用的帖子

I'm trying to view the history of my branch which includes merge commits (specifically what changed) and I found a very useful post here git show of a merge commit that tells me to use git show --first-parent

仍然让我感到困惑的是,为什么-first-parent 不是 git show 的默认值,或者甚至是为什么其他任何行为都没有用的原因.如果我在特定提交的特定分支上查看历史记录,那么我唯一想知道的就是该分支版本与上一个分支之间的区别.

What's still confusing me is why --first-parent isn't the default for git show, or even why any other behavior is useful at all. If I'm looking in my history on a specific branch at a specific commit, the only thing I ever want to know is the difference between that version of the branch and the previous one.

当然,编写git命令可能是为了给作者带来方便,这些作者没有说出最终用户的实际需求,但是我怀疑这是有适当原因的.有人可以解释为什么,由于对git有更好的了解,我可能不想一直使用-first-parent .

Of course it could be that git commands are written for the convenience of the authors who don't give a shit what their end users actually want, but I suspect that there is a proper reason. Could someone explain why, with a better knowledge of git, I might not want to use --first-parent all the time.

推荐答案

好吧,我想这比您想象的要糟,因为-第一父级的行为不是 您描述为仅有用"行为的行为.通常情况是一样的,但这取决于与存储库一起使用的分支/合并工作流.

Well, I guess it's worse than you think, because the behavior of --first-parent is not the behavior you describe as the "only useful" behavior. It often works out to be the same, but that depends on the branch/merge workflow used with the repo.

(其中没有一个与作者的便利性"有关,他们确实有能力将选项设置为默认选项,如果这样做确实有意义).

(None of which has anything to do with the "convenience of the authors", who are quite capable of making an option the default if it actually made sense to do so.)

第一父级"不是 ,意思是我所在分支的父级".实际上,git中的 nothing 意思是我所在分支的父级",因为在git中,分支和提交之间的关系无法正常工作.如果可以从分支到达合并,则其所有父节点也是如此.通常,确实有一个父级曾经一次被当前分支直接指向.这是git既不了解也不在乎的事情.

The "first parent" does not mean "the parent from the branch I'm on". In fact, nothing in git means "the parent from the branch I'm on", because in git the relationship between branches and commits doesn't work that way. If a merge is reachable from a branch, so are all of its parents. It may typically be true that one of those parents was, at one time, pointed to directly by the current branch. That is something git neither knows nor cares about.

第一父级"仅表示在合并的父级列表中首先记录的提交",这与refs的当前状态无关.

"First parent" just means "the commit that was recorded first in the merge's parent list", which has nothing to do with the current state of refs.

现在,如果使用瓷器命令 git merge 生成合并提交,则当前签出的所有内容都将记录为第一个父项.如果执行此操作时未处于分离的头部状态(意味着您已签出分支),则该分支将前进到合并提交.因此,通常可以得出以下结论:您正在读取分支历史记录,并且经过了许多合并提交,这些合并提交是合并到"当前分支中的.

Now, if you use the porcelain command git merge to produce a merge commit, then whatever is currently checked out will be recorded as the first parent. And if you're not in detached head state when you do this - meaning you have a branch checked out - then that branch will advance to the merge commit. So it often works out that you're reading a branches history, and you pass through a number of merge commits that were merges "into" the current branch.

但是假设在将 branch2 合并到 master 之后,您立即说

But suppose right after merging branch2 into master you then say

git checkout branch2
git merge master

会将 branch2 快进到合并提交中.现在,在 branch2 仍签出的情况下

which will fast-forward branch2 onto the merge commit. Now, with branch2 still checked out

git show --first-parent

,即使您不是签出的分支,您也会看到来自" master 的父级.

and you'll see the parent that "came from" master even though that's not the branch you have checked out.

您可以说但是在我的工作流程中,我从没有那样做,所以我的假设成立了".好吧,在这种情况下,您的假设对您而言是有效的.但是git并不仅仅是为您而写的,它并没有假设每个人都按照您的工作方式来工作.

And you can say "but in my workflow, I never do that, so my assumption holds". Well, in that case your assumption holds for you. But git wasn't written just for you, and it doesn't make assumptions that everyone works the way you happen to work.

git show的目的是提供有关指定提交的信息.-first-parent (在此和许多其他命令中)的目的是在仅查看合并的第一个父项才能生成图片的情况下限制该信息更清晰.需要对信息进行限制,以便git在使图片更少清晰的情况下不会应用该信息.

The purpose of git show is to give information about the specified commit. The purpose of --first-parent - in this and numerous other commands - is to limit that information in cases where looking only at the first parent of a merge makes the picture more clear. That limiting of information needs to be requested so that git doesn't apply it when it would make the picture less clear.

但是好吧,即使-first-parent 并不完全代表您所说的想要 show 的默认行为,为什么不让 show 表现出您的描述方式吗?好吧,因为git存储数据的方式,所以没有办法识别我当前分支的父级",并且如果您更改了存储数据的方式以实现这一点,那么它将对git施加新的限制,这是比原来更大的问题.您要解决的问题.

But ok, even though --first-parent doesn't mean quite what you've said you want shows default behavior to be, why not make show behave the way you describe? Well, because the way git stores data, there's no way to identify "the parent from my current branch", and if you changed the way the data is stored to make that possible, it would impose new limitations on git that are bigger problems than what you're trying to solve.

这篇关于为什么--first-parent不是git show的默认显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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