当git commit打开邮件编辑器显示一个简要的状态,这样的事情:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is ahead of 'origin/master' by 26 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: Showcase/src/com/gigantt/BorderArea.mxml
# modified: Showcase/src/com/gigantt/Client.mxml
# modified: Showcase/src/com/gigantt/GraphItem.mxml
#
Run Code Online (Sandbox Code Playgroud)
我如何调整git以显示要提交的差异?我知道它可能是一个很长的差异,但仍然......非常有用.
Ala*_*avi 145
该--verbose(或-v)标志git commit将显示这将是犯下的DIFF:
git commit --verbose
tom*_*ski 31
没有足够的声誉来回复Alan的答案,但对于Idan和其他任何人我只是尝试了它并且提交消息中的diff行没有明确注释掉.但是,他们仍然没有出现在最后的提交消息中,谢天谢地.
$ git commit --verbose
在我的编辑器中:
Feeling a bit pessimistic now.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README
#
diff --git a/README b/README
index af5626b..c62237e 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-Hello, world!
+Goodbye, world!
Run Code Online (Sandbox Code Playgroud)
(注意缺少#前面的差异线)
然后是实际的提交消息:
$ git log -n 1
commit ad21a2655ef6d8173c2df08dc9893055b26bc068
Author: Tom Jakubowski <tom@crystae.net>
Date: Thu Oct 27 19:12:54 2011 -0700
Feeling a bit pessimistic now.
Run Code Online (Sandbox Code Playgroud)
显然,git show仍会显示差异,但那是因为它总是用于提交.:)
我在.git/hooks/prepare-commit-msg中添加了以下行来获取注释掉的diff:
#!/bin/bash
if [ "$2" == "" ] ; then
git diff --staged -p --stat 2> /dev/null | awk '{ printf "#"; print}' >> "$1" 2>/dev/null
fi
Run Code Online (Sandbox Code Playgroud)
这样你不仅可以注释掉diff,还可以添加更多信息(比如stat选项).
编辑:另外git commit --verbose不包含提交消息的差异,这样做没有#s.
确保始终存在此行为的最简单方法是将此部分添加到您的git config文件中:
[commit]
verbose = true
Run Code Online (Sandbox Code Playgroud)
您可能需要将编辑器配置为以diff模式实际显示(用于语法突出显示).我使用Notepad2作为Windows Notepad的替代品,并-s diff适当地设置颜色方案(红色表示已删除的行等):
[core]
editor = C:/Windows/system32/notepad.exe -s diff
Run Code Online (Sandbox Code Playgroud)
如果要在提交时始终看到差异,可以将以下内容添加到~/.gitconfig文件中:
[alias]
commit = commit -v
Run Code Online (Sandbox Code Playgroud)