我已经安装了新Ubuntu 12.04
的并使用git
. 当我这样做时git commit
,它用编辑器打开了一些文件nano
让我输入提交描述。
问题:
1)我可以使用vi
而不是nano
以及如何使用?
2)我应该附加建议的内容还是替换它?
您必须更改默认编辑器。这可以使用以下命令从命令行完成:
export EDITOR=vim
用您想要使用的编辑器的名称替换 vim。
编辑:我还应该注意,它通常用于git commit -m "commit message here"
代替git commit
,因为提交消息通常不是很长,并且不需要拉起整个编辑器来写一个快速的句子。
其他人已经指出如何更改编辑器,但这里有一些提示。
首先,空白提交消息中止提交。如果您意识到在输入信息时忘记了某些内容,这将非常方便。
其次,有一种用于创建提交消息的非正式标准,这是一个好主意。通过遵循标准,您可以确保日志、补丁等运行良好。标准是这个
The first line should be a brief summary no more than 72 chars long (some say 50).
Then there should be a blank line, followed by a longer explanation which
can go on to as many lines as you like and use * or - etc. for bullet
points.
- Lines should be hard-wrapped with a carriage return.
- They should not be longer than 72 characters.
这些只是指导方针,git 不会强制执行它们,并且项目的期望存在一些变化,但它们是很好的指导方针。
1) 是的,安装 vi(m) 并使用sudo update-alternatives –config editor
2) 随心所欲,以 an 开头的#
行将被忽略
放入export EDITOR=vi
您的.profile
文件以设置您的默认编辑器。
通常,提交消息应该很短,因此通常最好用简短的描述替换所有这些内容。它真的在那里,所以你可以看到你在做什么。
你可以试试这个:$ git config --global core.editor vi
因为 vi 是预先安装在 fresh 上的Ubuntu 12.04
。
来自官方手册git config
:
core.editor
Commands such as commit and tag that lets you edit messages by
launching an editor uses the value of this variable when it is set,
and the environment variable GIT_EDITOR is not set. See git-var(1).
来自官方手册git commit
:
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The <mode> can be one of verbatim, whitespace, strip, and default.
The default mode will strip leading and trailing empty lines and
#commentary from the commit message only if the message is to be
edited. Otherwise only whitespace removed. The verbatim mode does
not change message at all, whitespace removes just leading/trailing
whitespace lines and strip removes both whitespace and commentary.
从这里可以看出,只有在要编辑消息时,默认模式才会从提交消息中去除前导和尾随的空行和#commentary。
commit.status
A boolean to enable/disable inclusion of status information in the
commit message template when using an editor to prepare the commit
message. Defaults to true.
和
commit.template
Specify a file to use as the template for new commit messages.
"~/" is expanded to the value of $HOME and "~user/" to the specified
user’s home directory.