Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将编辑器与“一起使用”;git提交“;?_Git_Commit_Vi_Nano - Fatal编程技术网

如何将编辑器与“一起使用”;git提交“;?

如何将编辑器与“一起使用”;git提交“;?,git,commit,vi,nano,Git,Commit,Vi,Nano,我已经安装了全新的ubuntu12.04,并用git初始化了一些项目。当我执行git提交时,它使用nano编辑器打开了一些文件,让我输入提交描述 问题: 1) 我可以用vi代替nano吗?如何使用 2) 我应该添加建议的内容还是替换它?1)是的,安装vi(m)并使用sudo更新替代方案–配置编辑器 2) 如果您愿意,以#开头的行将被忽略将导出编辑器=vi放入.profile文件以设置默认编辑器 提交消息通常应该是简短的,所以通常最好用简短的描述替换所有这些内容。它确实存在,只是为了让您可以看到您

我已经安装了全新的
ubuntu12.04
,并用
git
初始化了一些项目。当我执行
git提交
时,它使用
nano
编辑器打开了一些文件,让我输入提交描述

问题:

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

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

1)是的,安装vi(m)并使用
sudo更新替代方案–配置编辑器


2) 如果您愿意,以
#
开头的行将被忽略

导出编辑器=vi
放入
.profile
文件以设置默认编辑器


提交消息通常应该是简短的,所以通常最好用简短的描述替换所有这些内容。它确实存在,只是为了让您可以看到您正在提交的内容。

您必须更改默认编辑器。可以使用以下命令从命令行执行此操作:

export EDITOR=vim
用您想要使用的编辑器的名称替换vim


编辑:我还应该注意,使用
git commit-m“commit message here”
而不是
git commit
,这是很常见的,因为commit messages通常不会很长,也不需要拉动整个编辑器来写一个简短的句子。

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

首先,空白提交消息中止提交。如果你在输入信息时发现自己忘记了什么,这是很方便的

其次,有一种非正式的标准用于创建提交消息,这是一个好主意。通过遵循标准,您可以确保日志、修补程序等工作正常。标准是这样的

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: 您可以试试这个:
$git config--global core.editor vi
,因为vi是预装在fresh
Ubuntu 12.04
上的

从《git配置官方手册》

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的官方手册
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.


请注意,Ubuntu 12.04很古老。14.04是最新版本(更新两年!),也是一个长期支持版本。它提供了一个更新版本的Git。您可能需要考虑升级。
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.