强制git日志显示所有提交,包括精心挑选的提交

问题描述 投票:0回答:1

在撰写本文时,我只是找到了这个问题的答案,但仍会发布给他人分享。

测试场景

我创建了一个带有两个分支合并的小型测试存储库,其中一个分支包含另一分支中已经存在的精选的提交版本。

((我使用rebase -ir人工制作此测试历史记录)

常规的git日志显示了完整的历史记录:

> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8
*   b1008ab1 (HEAD -> master) Merge 'alternative' into master.
|\  
| * 22a3a296 Add x.txt
| * 0af2f788 Add y.txt
* | 3856adbf Add y.txt
* | 8543e6d8 Add x.txt
|/  
* e7696150 Initial commit.

((我为此使用git lol别名,但是对于这个问题,我将列出所有选项)

但是,过滤到其中一个文件的git日志仅显示分支主要部分(第一个合并父级)中相应的提交之一:

> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 x.txt
* 8543e6d8 Add x.txt

问题

如何强制git log显示修改相应文件的所有提交,包括重复的/樱桃挑选的提交?

到目前为止我尝试过的

我在git help log中签入,发现--cherry-mark--cherry-pick--left-only--right-only,但这些都没有真正的区别。

git git-log
1个回答
0
投票

使用git log --full-history --simplify-merges

--full-history已经可以满足您的要求,但是它列出了很多合并,提供的信息很少。

添加--simplify-merges隐藏了其中一些合并。

检查git help log以获取详细说明。

这仅在提供路径时有所不同。没有提供路径,无论如何它已经显示了所有经过精心挑选的提交。

> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- x.txt
* 8543e6d8 Add x.txt
> git log --simplify-merges --full-history --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- x.txt
*   0de2139f (HEAD -> master) Merge 'alternative' into master.
|\  
| * 22a3a296 Add x.txt
* 8543e6d8 Add x.txt

有趣的是,此路径也可以是全局通配符。

> git log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- *
* 2c970073 Add z.txt
* 22a3a296 Add x.txt
* 0af2f788 Add y.txt
* e7696150 (tag: BEGIN) Add a jpg image
> git log --simplify-merges --full-history --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 -- *
*   0de2139f (HEAD -> master) Merge 'alternative' into master.
|\  
| * 2c970073 Add z.txt
| * 22a3a296 Add x.txt
| * 0af2f788 Add y.txt
* | 3856adbf Add y.txt
* | 8543e6d8 Add x.txt
|/  
* e7696150 (tag: BEGIN) Add a jpg image

注意事项

[我发现在具有复杂历史记录的大型回购中,git log--full-history的速度要慢得多。

如果指定了提交范围,例如--simplify-merges,那么即使使用git log <parameters> master..develop -- <path>,也会显示更多合并。

有用的别名

参数与--simplify-merges参数结合使用非常有用。我已经将其作为--graphlol别名(有些博客帖子中人们想出了这些名称,但我没有发明它们)。

所以我现在将其添加到我的全局git配置中:

lola

git log以这种方式表现好吗?

也许不是。在下面查看torek的评论。

© www.soinside.com 2019 - 2024. All rights reserved.