也许您之前在第一次创建 git 存储库时添加并提交了?
我能够通过以下方式重现这一点:
durrantm.../aaa$ git init
Initialized empty Git repository in /home/durrantm/play/aaa/.git/
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg
drwxrwxr-x 3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x 7 durrantm 4096 Oct 31 22:29 .git/
durrantm.../aaa$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ggg
nothing added to commit but untracked files present (use "git add" to track)
durrantm.../aaa$ git add .
durrantm.../aaa$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: ggg
#
durrantm.../aaa$ git commit
[master (root-commit) 953c83f] new
1 file changed, 1 insertion(+)
create mode 100644 ggg
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg
drwxrwxr-x 3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x 8 durrantm 4096 Oct 31 22:29 .git/
durrantm.../aaa$ git init
Reinitialized existing Git repository in /home/durrantm/play/aaa/.git/
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg
drwxrwxr-x 3 durrantm 4096 Oct 31 22:29 ./
drwxrwxr-x 8 durrantm 4096 Oct 31 22:30 .git/
durrantm.../aaa$ git add .
durrantm.../aaa$ git status
# On branch master
nothing to commit (working directory clean)
durrantm.../aaa$
durrantm.../aaa$ git commit
# On branch master
nothing to commit (working directory clean)
请注意您所看到nothing to commit
的 a 之后的结尾如何。git add .
一个“修复”是删除 git 存储库并重新开始,当您这样做时,您可以正常提交最终版本,例如:
durrantm.../aaa$ rm -rf .git/
durrantm.../aaa$ l
total 12
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg
drwxrwxr-x 2 durrantm 4096 Oct 31 22:34 ./
durrantm.../aaa$ git init
Initialized empty Git repository in /home/durrantm/play/aaa/.git/
durrantm.../aaa$ l
total 16
drwxrwxr-x 14 durrantm 4096 Oct 31 22:28 ../
-rw-rw-r-- 1 durrantm 11 Oct 31 22:29 ggg
drwxrwxr-x 3 durrantm 4096 Oct 31 22:34 ./
drwxrwxr-x 7 durrantm 4096 Oct 31 22:34 .git/
durrantm.../aaa$ git add .
durrantm.../aaa$ git commit
[master (root-commit) 380863a] wewew
1 file changed, 1 insertion(+)
create mode 100644 ggg