git blame
命令显示的提交哈希缩写为比其他命令长一个字符的长度。例如:
$ git log --oneline
9fb6f706 (HEAD -> master) second commit
0af747a8 first commit
$ git blame foo
9fb6f7064 (gilles 2020-11-15 12:28:09 +0100 1) revised
^0af747a8 (gilles 2020-11-15 12:27:41 +0100 2) world
我经常从 blame
输出中复制粘贴一个缩写的散列,并在日志或交互式 rebase 中的提交集中搜索它。但是因为缩写在git blame
输出中多了一个字符,所以我必须记得删除最后一个字符,否则搜索找不到任何东西。
对于脚本,我会使用未缩写的哈希和瓷器格式。但对于交互式使用,我想使用缩写的哈希值。
设置 core.abbrev
选项没有帮助:git blame
添加了一个选项。设置 core.abbrev
并调用 blame --abbrev
用一个少一个的值工作,但这不是一个好的解决方案,因为我失去了 git 的启发式方法来确定一个好的解决方案短提交 ID 的长度,我必须显式传递此选项或使用不同的命令名称作为别名。
我怎样才能让一个普通的 git blame
对缩写的提交 ID 使用与其他 git 命令相同的长度?
最佳答案
感谢您挖掘源代码。恐怕您唯一的解决方案 – 而解决方法是定义自定义别名。
git config --global alias.blame2 '!git -c core.abbrev=6 blame'
关于git - 对 git blame 使用与其他命令相同的提交缩写长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64849093/