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

时间:2020-04-05 03:48:17

标签: git git-log

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

测试场景

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

(我用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,但是这些都没有真正的作用。

1 个答案:

答案 0 :(得分:1)

使用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,也会显示更多合并。

有用的别名

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

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

[alias]
  lol = log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8
  lola = log --graph --decorate --pretty=oneline --abbrev-commit --abbrev=8 --all
  lolf = log --graph --decorate --pretty=oneline --abbrev-commit --full-history --simplify-merges --abbrev=8
  lolaf = log --graph --decorate --pretty=oneline --abbrev-commit --full-history --simplify-merges --abbrev=8 --all

git log以这种方式行事好吗?

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