通过合并获取分支的历史记录

Getting history of branch with merges

假设我们有一个分支 master,我想查看 master 分支指向的历史。通常我可以用 git log --first-parent 来做到这一点。但是假设我们有另一个分支暂存。 Staging 合并到 master 中,然后 master fast forward 上的某个人合并 staging。现在我们不能再通过仅跟随第一个父节点来获得 master 过去指向的历史。问题是我们现在在 master 的历史中有一个提交,其中 master 的真实历史是通过跟随第二个父级找到的。

在我看来,只要使用默认合并消息,我们仍然可以获得该历史记录。该方法将是:从某个提交开始,除非提交消息是“Merge branch master ...”,否则跟随第一个父节点;如果提交消息是“Merge branch master”,那么只跟随第二个父节点。

有没有一种方法可以使用与 git log 不同的选项来做到这一点?一般来说,在 git 中,通过查看每个提交并根据选择显示它、不显示它以及跟随哪个父项来构建日志的最简单方法是什么?这可以由 git 本身完成,还是我应该查看例如 python 的 git 库?

Is there a way to [choose the parent to follow] with different options to git log?

没有

In general what is the easiest way in git to construct a log by looking at each commit and based on that choosing to show it, not show it, and which parent to follow? Can this be done by git itself or should I look into for example a git library for python?

这当然是一个选择。或者,您可以下载 Git 的 Git 存储库并尝试向其中添加代码。最后一个(最慢到 运行,但最容易编写)选项是使用类似 git rev-list --parents 的东西,读取它打印的哈希 ID,并在 [= 中编写你自己的 git log 变体21=] 脚本或类似的。