如何使用编辑器" git commit"?

时间:2014-07-05 14:12:03

标签: git commit vi nano

我安装了新的Ubuntu 12.04并使用git初始化了一些项目。当我git commit时,它打开了一个带有nano编辑器的文件,供我输入提交说明。

问题:

1)我可以使用vi代替nano吗?

2)我应该追加建议的内容还是替换它?

5 个答案:

答案 0 :(得分:2)

其他人已经指出了如何更改编辑器,但这里还有一些提示。

首先,空白提交消息会中止提交。如果您在键入消息时意识到忘记了某些内容,这将非常方便。

其次,有一种非正式的标准用于创建提交消息,这是一个坚持的好主意。遵循标准,您可以确保日志,补丁等运行良好。标准是这个

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 :(得分:1)

1)是,安装vi(m)并使用sudo update-alternatives –config editor
2)按照您的意愿,以#开头的行将被忽略

答案 2 :(得分:1)

export EDITOR=vi放入.profile文件中以设置默认编辑器。

通常,提交消息应该很短,因此通常用简短的描述替换所有内容会更好。它真的存在,所以你可以看到你的承诺。

答案 3 :(得分:1)

您必须更改默认编辑器。这可以使用以下命令从命令行完成:

export EDITOR=vim

用您想要使用的编辑器的名称替换vim。

编辑:我还应该注意,使用git commit -m "commit message here"代替git commit是常见的,因为提交消息通常不会很长,并且不需要提取整个编辑器写一个快句。

答案 4 :(得分:1)

问题1:

您可以尝试这样做:$ git config --global core.editor vi因为vi已预先安装在新的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).

问题2:

来自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.
相关问题