我爱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
存储库,该存储库使用clever branch and merge strategy。使用这种方法,--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
是以下别名,或实际上是一对别名(也可以对它们进行简化或改进,因为我不完全满意它们的复杂性,因此不能获得奖励!):< / p>
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
,但是只显示 second 父级的第一次提交,这告诉了我确切的内容实际上已合并了commit,而不必查看该提交的所有父级。因此,我想要的是别名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)
克隆git.git
并将主服务器倒退到041f5ea1cf987a4068ef5f39ba0a09be85952064,以复制上述命令中给出的输出。
答案 0 :(得分:0)
Git无法选择专门执行您想要的操作。通常会要求这样做,但是它没有实现(而且不可能在上游)。
--topo-order
会执行与您想要的单提交分支非常相似的操作,因为它将阻止将分支上的提交与其他分支穿插在一起。如果您有多个提交分支,则无法选择要执行的操作。
答案 1 :(得分:0)
以下是最后20条主线提交以及任何合并分支的提示的方法:
git rev-list --first-parent --parents HEAD \
| sed '/ [^ ]* /!d;s,[^ ]* [^ ]* ,,;s, ,\n,g' >.git/info/grafts
git log --graph --decorate --oneline @~20..
rm .git/info/grafts
sed
为嫁接文件的主线提交的所有第二个或更大父行创建一行,专门重写了仅本地祖先的列表,用于记录的祖先不立即发送的情况目的。 “它看起来很愚蠢,但是有效。”
$ 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'