命令
有時候爲了減少提交日誌,並且添加的內容是與上次的內容屬於同一個提交內容的,爲了好維護,會將本次的提交追加到上次的提交中。使用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 實際目錄,使用變量引用。