git - Git log `--first-parent`,仅包含来自第二个父级的第一个合并提交
问题描述
背景
我喜欢git log --first-parent
,尤其是与--one-line
. 如此之多,以至于我将其别名为lgp
:
log --graph --abbrev-commit --decorate --format=format:'%C(yellow)%h%C(reset) %C(normal)%s%C(reset) %C(dim white)%an%C(reset) %C(dim blue)(%ar)%C(reset) %C(auto)%d%C(reset)' --first-parent
这给了我如下所示的输出:
$ git lgp -5
* 041f5ea1cf The third batch Junio C Hamano (2 weeks ago) (HEAD -> master, origin/master, origin/HEAD)
* 0c45fa32ec Merge branch 'br/commit-tree-parseopt' Junio C Hamano (2 weeks ago)
* f6c75e392e Merge branch 'jk/config-type-color-ends-with-lf' Junio C Hamano (2 weeks ago)
* 6b5688b760 Merge branch 'ma/clear-repository-format' Junio C Hamano (2 weeks ago)
* 83b13e284c Merge branch 'jk/virtual-objects-do-exist' Junio C Hamano (2 weeks ago)
此输出来自git.git
存储库,它使用巧妙的分支和合并策略。使用这种方法,--first-parent
允许显示干净的历史记录,每个合并主题(功能分支)的所有细节都被省略,但如果需要可以使用。例如,要查看从 合并的所有提交,请jk/virtual-objects-do-exist
运行以下命令:
git mergedtopiclg 83b13e284c
* f06ab027ef rev-list: allow cached objects in existence check Jeff King (5 weeks ago) (origin/jk/virtual-objects-do-exist)
* 7c0fe330d5 rev-list: handle missing tree objects properly Matthew DeVore (6 months ago)
* f1d02daacf list-objects: always parse trees gently Matthew DeVore (8 months ago)
* 9202489174 list-objects: refactor to process_tree_contents Matthew DeVore (8 months ago)
* f447a499db list-objects: store common func args in struct Matthew DeVore (8 months ago)
mergedtopiclg
是以下别名,或者实际上是一对别名(请随意对这些别名进行简化或改进,因为我对它们的复杂程度并不完全满意,以获得额外的支持!):
oldest-ancestor = !bash -c 'diff --old-line-format= --new-line-format= <(git rev-list --first-parent \"${1:-master}\") <(git rev-list --first-parent \"${2:-HEAD}\") | head -1' -
mergedtopiclg = !sh -c \"git lg $(git oldest-ancestor $1^2 ${2:-master})..$1^2\" -
最后,问题
但是,现在,有时我喜欢使用--first-parent
,但只显示来自第二个父级的第一个提交,它可以准确地告诉我实际合并了哪些提交,而不必查看该提交的所有父级。所以,我想要的是一个别名lgpp
,它会给我这个输出:
$ git lgpp -5
* 041f5ea1cf The third batch Junio C Hamano (2 weeks ago) (HEAD -> master, origin/master, origin/HEAD)
(4 weeks ago) (origin/br/commit-tree-parseopt)
* 0c45fa32ec Merge branch 'br/commit-tree-parseopt' Junio C Hamano (2 weeks ago)
|\
| * cbdeab98e8 commit-tree: utilize parse-options api Brandon Richardson * f6c75e392e Merge branch 'jk/config-type-color-ends-with-lf' Junio C Hamano (2 weeks ago)
* f6c75e392e Merge branch 'jk/config-type-color-ends-with-lf' Junio C Hamano (2 weeks ago)
|\
| * cd8e7593b9 config: document --type=color output is a complete line Jeff King (4 weeks ago) (origin/jk/config-type-color-ends-with-lf)
* 6b5688b760 Merge branch 'ma/clear-repository-format' Junio C Hamano (2 weeks ago)
|\
| * e8805af1c3 setup: fix memory leaks with `struct repository_format` Martin Ågren (5 weeks ago) (origin/ma/clear-repository-format)
* 83b13e284c Merge branch 'jk/virtual-objects-do-exist' Junio C Hamano (2 weeks ago)
|\
| * f06ab027ef rev-list: allow cached objects in existence check Jeff King (5 weeks ago) (origin/jk/virtual-objects-do-exist)
将 master克隆git.git
并倒带到 041f5ea1cf987a4068ef5f39ba0a09be85952064 以复制上述命令中给出的输出。
解决方案
以下是如何进行最后 20 次主线提交和任何合并分支的提示:
git rev-list --first-parent --parents HEAD \
| awk '{ for (i=2; i<NF; ) print $++i }' >.git/info/grafts
git log --graph --decorate --oneline @~20..
rm .git/info/grafts
为awk
移植文件的主线提交的所有第二个或更大的父母创建一行,一个仅本地祖先的列表专门针对记录的祖先不能立即服务的情况重写。“它看起来很愚蠢,但它确实有效。”
$ git log --graph --decorate --oneline @~20..
* d638ded169 (HEAD -> master) options
* 041f5ea1cf (origin/master, origin/HEAD) The third batch
* 0c45fa32ec Merge branch 'br/commit-tree-parseopt'
|\
| * cbdeab98e8 (grafted) commit-tree: utilize parse-options api
* f6c75e392e Merge branch 'jk/config-type-color-ends-with-lf'
|\
| * cd8e7593b9 (grafted) config: document --type=color output is a complete line
* 6b5688b760 Merge branch 'ma/clear-repository-format'
|\
| * e8805af1c3 (grafted) setup: fix memory leaks with `struct repository_format`
* 83b13e284c Merge branch 'jk/virtual-objects-do-exist'
|\
| * f06ab027ef (grafted) rev-list: allow cached objects in existence check
* 27cdbdd134 Merge branch 'jk/no-sigpipe-during-network-transport'
|\
| * 143588949c (grafted) fetch: ignore SIGPIPE during network operation
* ea327760d3 Merge branch 'jk/fsck-doc'
|\
| * 8d8c2a5aef (grafted) fsck: always compute USED flags for unreachable objects
* 88255bba45 Merge branch 'js/stress-test-ui-tweak'
|\
| * f545737144 (grafted) tests: introduce --stress-jobs=<N>
* 9fbcc3d203 Merge branch 'js/rebase-orig-head-fix'
|\
| * cbd29ead92 (grafted) built-in rebase: set ORIG_HEAD just once, before the rebase
* 1b8f4dc580 Merge branch 'jk/bisect-final-output'
|\
| * b02be8b901 (grafted) bisect: make diff-tree output prettier
* 3cef67694c Merge branch 'ab/makefile-help-devs-more'
|\
| * 6d5d4b4e93 (grafted) Makefile: allow for combining DEVELOPER=1 and CFLAGS="..."
* 0e94f7aa73 Merge git://ozlabs.org/~paulus/gitk
|\
| * dec59817c1 (grafted) gitk: Update Bulgarian translation (317t)
* e902e9bcae The second batch
* be9f1c0224 Sync with maint
|\
| * aeb582a983 (grafted, origin/maint) mingw: allow building with an MSYS2 runtime v3.x
* a07baf33e3 Merge branch 'js/rebase-recreate-merge'
|\
| * dbf47215e3 (grafted) rebase docs: fix "gitlink" typo
* d61ddb5189 Merge branch 'js/untravis-windows'
|\
| * 50b206371d (grafted) travis: remove the hack to build the Windows job on Azure Pipelines
* 443442ec71 Merge branch 'rd/gc-prune-doc-fix'
|\
| * 716a5af812 (grafted) docs/git-gc: fix typo "--prune=all" to "--prune=now"
* c0d97d299e Merge branch 'js/find-lib-h-with-ls-files-when-possible'
|\
| * 92b88eba9f (grafted) Makefile: use `git ls-files` to list header files, if possible
* 1de413bc1d Merge branch 'rj/hdr-check-gcrypt-fix'
推荐阅读
- iphone - 当 iPhone 从纵向变为横向时出现白条
- javascript - 当新用户登录时,如何确保我的菜单刷新?尝试显示正确的项目(管理员用户的管理员导航)
- scala - SCALA -- 使 groupBy + sum 查找零列
- performance - Elasticsearch:在同一个分片上折叠文档是否会在折叠时提高性能?
- c# - 如何将图像上传到数据库并将其显示回视图 ASP.NET Core MVC
- kdb - “prev 5 mavg col1”的 kdb/q 功能更新
- reactjs - 在 foreach 中运行 firebase 请求,但希望等待结果继续进行(异步/等待不起作用)
- scheme - 从 If 条件调用函数
- node.js - 如何让 Pinterest API 接受我的重定向 URL?
- c# - 如何创建一组相关属性?