任何时候我在本地做出更改并执行
git commit --amend
,然后使用:x
保存并退出vim,或者仅仅执行git commit --amend --no-edit
都不起作用。没有任何本地更改被提交或暂存。我完全不知道如何可能发生这种情况。其他rebase
操作正常使用编辑器。
以下是完整的可工作的重现步骤:
amendwtf|master ⇒ ls
file
amendwtf|master ⇒ git status
On branch master
nothing to commit, working tree clean
amendwtf|master ⇒ echo 'a change appears' > file
amendwtf|master⚡ ⇒ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
amendwtf|master⚡ ⇒ git commit --amend --no-edit
[master 3b577b8] initial commit
Date: Thu Mar 14 09:49:08 2019 -0400
1 file changed, 1 insertion(+)
create mode 100644 file
amendwtf|master⚡ ⇒ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
amendwtf|master⚡ ⇒
Git和Vim版本:
amendwtf|master⚡ ⇒ git --version
git version 2.21.0
amendwtf|master⚡ ⇒ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
-a
。相反,先运行git add -u
——这就是git commit -a
所做的,但现在您可以运行git status
并确保输出反映了您希望在下一个git commit
中发生的情况,无论是使用--amend
还是不使用。 (当然,一旦您熟悉了git add -u
,并且确定它将执行您想要的操作,那么git commit -a
就没问题了。不过我自己仍然使用-u
!) - torek