假设我有两个完全相同的提交,但它们的消息不同,我如何在 git 中看到它?
如何制作这个;假设我在 master 上,在任何提交上;
git checkout -b test
git commit --amend
// now edit the commit message
git diff master
这显示了一个空输出。我发现在提交消息中看到这种差异的唯一方法是:
git show --stat master > m
git show --stat > t
diff m t
产生这样的输出(我确实稍微修改了 git log 输出格式):
1c1
< 65fb678 - (HEAD, test) add bcdef (Fri, 8 Jan 2016 11:23:51 +0100) <Chris Maes>
---
> 7f9c3ee - (master) add bcd (Wed, 6 Jan 2016 11:28:10 +0100) <Chris Maes>
是否有任何 git 命令允许仅查看提交消息的差异(有或没有正常的 git 输出)?
注意 我的问题类似于 this question , 但我一直在寻找允许这样做的 git 命令。
最佳答案
这对我有用:
diff -w <(git rev-list --max-count=1 --format=%B SHA1) <(git rev-list --max-count=1 --format=%B SHA2)
-
-w
忽略空格差异。 <( ... )
语法创建一个临时命名管道,它使git show
的标准输出命令看起来和行为都像一个文件,允许 diff 对预期的输入类型进行操作。-
--format=%B
显示提交消息的原始消息头+正文
您可以替换 diff -w
与 wdiff
进行逐字比较。
编辑
如果你真的想要一个git
命令,将此 git 别名添加到 ~/.gitconfig
:
[alias]
msgdiff = "!bash -c '[ $# = 2 ] && diff -w <(git rev-list --max-count=1 --format=%B \"$1\") <(git rev-list --max-count=1 --format=%B \"$2\")' -"
然后你可以做
git msgdiff SHA1 SHA2
关于git 显示提交消息之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674771/