首页 > git commit 的时候如何添加大段的注释

git commit 的时候如何添加大段的注释

为什么我在用osx上的git的时候用

git commit -a

会出现

Aborting commit due to empty commit message.

的确会跳出编辑器让我输入commit信息,但是保存之后tig中依然没有提交的信息,也就是之前被那个空消息错误给打断了,但是照理来说不是可以通过这个方法来编写大段的commit信息么,难道需要做什么配置,求教


楼主使用过 git gui 没?不过,git commit -m "your description"命令方便下次快捷提交而已。


git config --global core.editor "[your editor] -w"

-w 通知Git使用自已指定的编辑器

Git使用方法:

touch README.md
git init
git add README.md
# git commit -m "first commit" # 命令行添加提交信息
git commit # 编辑器添加提交信息

首先,使用下面这个命令来设置git默认的编辑器,其中的“editor”替换成你自己的编辑器,如Vim、Emacs、gedit、subl等:

git config --global core.editor "editor -w"

然后,在做提交的时候使用命令不要写"-m"参数,直接写成git commit这样子就行,这样就会自动打开你刚才指定的编辑器,你可以在里面添加大段注释。


git commit -am "bla bla bla"


可以查看Git帮助。
-m , --message=
Use the given as the commit message.

根据给定的信息进行注释,注释内容要用双引号扩起来
-a, --all
Tell the command to automatically stage files that have been
modified and deleted, but new files you have not told git about are
not affected

列出所有修改和删除的文件,但是新文件并不列出。


git commit
然后就写你的提交注释吧。
注:第一行尽量简洁吧,控制在 50 个字符内,然后空一行,再继续写详细的注释。

另,可以参考这个:「写出好的 commit message」


用macvim做commit时的编辑器,用-f参数能避免下面的提示.-w无效.

Aborting commit due to empty commit message.

在终端修改git config如下

git config --global core.editor "/bin/mvim -f"
【热门文章】
【热门文章】