git 显示提交消息之间的差异

标签 git git-diff

假设我有两个完全相同的提交,但它们的消息不同,我如何在 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 -wwdiff进行逐字比较。

编辑

如果你真的想要一个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/

相关文章:

git - 如何在 git 中对当前头部的提交之间应用差异?

git - 服务器 Git 用户名在 GitHub.com 上的什么位置显示?

git - 将 git 与 VS Code 连接

git - 使用 Git 的最佳方式是什么,是通过 HTTPS 还是通过 SSH?

github - 如何从 GitHub 下载单个 commit-diff?

Git 提交补丁

git - 源树: Not able to push to my remote repo in GitHub

git - 将 Bitbucket 存储库从一个帐户复制到另一个 bitbucket 帐户

git - 如何注释 git 存储库?

git - 从 Git 中的多个提交中导出修改后的文件