git log – 在不相关的历史之间添加分隔符,特别是对于--oneline

标签 git git-log

我几乎每天都使用 Git。最流行的子命令之一是 git log .为了更好地查看,我使用稍微扩展的版本 git log --decorate --oneline --graph :

log --graph --decorate --date=relative --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an %C(auto)%s %d'

让我们创建一个简单的 repo,它有两个根——不相关的分支。

git init
git commit --allow-empty -m"asdf 1"
git commit --allow-empty -m"zxcv 2"
git commit --allow-empty -m"qwer 3"
git co --orphan another
git commit --allow-empty -m"uiop 8"
git commit --allow-empty -m"hjkl 9"
git nl --all

哪里nlnicelog 的简称,是前面介绍的第二个命令的别名。
enter image description here 乍一看,分支 another 是分支 master 的后代,但这是错误的。正如你在下一张照片中看到的 enter image description here 命令:log --graph --decorate --date=relative --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an <%ae> %C(auto)%d %GS %n%w(0,3,3)%s%n%+b'

问题

如何制作git log在不相关的历史之间添加分隔符?像那样:

 * f949c4f 6 minutes ago kyb hjkl 9  (HEAD -> another)
 * 5dea811 6 minutes ago kyb uiop 8 
 --
 * ca006bf 7 minutes ago kyb qwer 3  (master)
 * 73056fd 7 minutes ago kyb zxcv 2 
 * e0d91c1 7 minutes ago kyb asdf 1 

解决方法

一个明显的方法是使用多行格式,例如:

log --graph --decorate --date=relative --pretty=format:'%C(yellow bold)%h %C(green dim)%ad %C(blue)%an <%ae> %C(auto)%d %GS %n%w(0,3,3)%s'

注意 %n在格式字符串中。

enter image description here

最佳答案

没有,没有办法得到你想要的。如果您想尝试为 Git 编写代码来执行此操作,请克隆 Git 源的一个只读克隆——最明显的是 https://github.com/git/git。 - 并坚持下去。

(这真的很好,我时不时地想要它,但是实现它的困难会变得很明显,我从来没有想要它足够。:-) 不相关的历史并不是那么普遍,所以它的用处非常有限。)

关于git log – 在不相关的历史之间添加分隔符,特别是对于--oneline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57647163/

相关文章:

GIT 同一存储库不同机器上的不同分支

git - 为什么 `git diff` 不调用外部差异工具?

git - 无法应用 git 属性过滤器

git - 如何显示带有提交编号的 git 日志?

Git 跟踪文件中移动/删除的代码块

Git 工作流程 - 在推送到公共(public) repo 之前或之后 merge master?

git - 如何使用 git clone --depth 1 check out 远程分支?

Git 日志显示 HEAD 指向的确切位置?

git - 找出我们尝试挑选的提​​交的依赖项

git - 显示所有分支中单个文件的历史记录