将文件扩展名添加到COMMIT_EDITMSG

时间:2019-04-16 12:29:55

标签: git notepad++

git版本2.10.2.windows.1

我使用notepad ++作为git的提交编辑器。我想在运行git commit -v时使用Diff语言打开编辑器,这样我可以更轻松地浏览我的差异(差异高亮显示+ /-行不同)。打开进行编辑的git文件名为COMMIT_EDITMSG(无扩展名)。 Notepad ++无法将无扩展名的文件与一种语言本地关联(请参阅this question)。

如何配置git来更改它打开用于编辑提交的文件? git commit文档引用此文件,但仅描述其用途:

  

$ GIT_DIR / COMMIT_EDITMSG

     

此文件包含正在进行的提交的提交消息。如果git commit由于在创建提交之前出错而退出,则用户提供的任何提交消息(例如,在编辑器会话中)将在此文件中可用,但将在下次调用git commit时被覆盖。

1 个答案:

答案 0 :(得分:1)

Git doesn't provide a way to change the file name used for commit messages. It's hard-coded in the source and various pieces of the code (not to mention plugins and hooks) depend on these exact names.

Typically editors provide some sort of pattern matching to associate a file type with an arbitrary file name pattern. It sounds like Notepad++ doesn't, so you may need to use a plugin, a different technique, or a different editor for editing commit messages.

Vim, for example, supports "modelines" at the start and end of files to set file-level variables. You could add the following line to force a file to be highlighted using "diff" syntax:

# vi:syntax=diff

If you find a functional modeline-style plugin, as mentioned in the other question, you can use the prepare-commit-message hook to insert a modeline at the bottom, which will cause the file to be highlighted as you want.

相关问题