作为一个自然健谈的灵魂,我的总结线几乎总是超过50个字符.如何仅在提交消息和提交消息的sublime中对我的标题行强制执行50个字符的限制?有没有办法自定义设置? 最佳答案 像
sublime-text-git这样的插件会强加一个
soft wrap on git commit message:
{
"rulers": [70]
}
但这适用于所有线路,而不仅仅是第一条线路.
您可以修改该插件以在键入时更改颜色(但这需要一些python编程);这是an editor like vim does:
请记住,对于以前冗长的消息,您可以通过LESS选项以适当的长度查看它们.见“How to wrap git commit comments?”.
否则,如commented 0700所示,commit-msg
hook like this one(从Addam Hardy开始,在python中)是真正实施该策略的唯一解决方案.
#!/usr/bin/python
import sys, os
from subprocess import call
print os.environ.get('EDITOR')
if os.environ.get('EDITOR') != 'none':
editor = os.environ['EDITOR']
else:
editor = "vim"
message_file = sys.argv[1]
def check_format_rules(lineno, line):
real_lineno = lineno + 1
if lineno == 0:
if len(line) > 50:
return "Error %d: First line should be less than 50 characters " \
"in length." % (real_lineno,)
if lineno == 1:
if line:
return "Error %d: Second line should be empty." % (real_lineno,)
if not line.startswith('#'):
if len(line) > 72:
return "Error %d: No line should be over 72 characters long." % (
real_lineno,)
return False
while True:
commit_msg = list()
errors = list()
with open(message_file) as commit_fd:
for lineno, line in enumerate(commit_fd):
stripped_line = line.strip()
commit_msg.append(line)
e = check_format_rules(lineno, stripped_line)
if e:
errors.append(e)
if errors:
with open(message_file, 'w') as commit_fd:
commit_fd.write('%s\n' % '# GIT COMMIT MESSAGE FORMAT ERRORS:')
for error in errors:
commit_fd.write('# %s\n' % (error,))
for line in commit_msg:
commit_fd.write(line)
re_edit = raw_input('Invalid git commit message format. Press y to edit and n to cancel the commit. [y/n]')
if re_edit.lower() in ('n','no'):
sys.exit(1)
call('%s %s' % (editor, message_file), shell=True)
continue
break