Git追加本次提交到上次提交

Git 追加提交到上次提交

命令

有时候为了减少提交日志,并且添加的内容是与上次的内容属于同一个提交内容的,为了好维护,会将本次的提交追加到上次的提交中。使用git 命令如下:

git add . (添加提交内容)
git commit --amend (追加到上次提交)

使用–amend 后会到编辑页面,可以编辑提交日志,编辑后:wq! 保存编辑并退出。如无需编辑直接 :q!退出即可。 或使用如下命令不进入编辑页面

git commit --amend --no-edit 

Q&A

1、提交后出现如下错误:

error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

原因:之前没有配置 core.editor 选项。
配置core.editor 选项git config --global core.editor /usr/bin/vim
后再次运行git commit --amend 即可。

2、配置core.editor 后依然出现 1 的错误,那有可能是vim 有修改,或使用macvim 替换。
解决:使用如下命令git config --global core.editor $(which vim) 不指定vim 实际目录,使用变量引用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章