Git 表示“1 个文件已更改,0 个插入 (+),0 个删除 (-)”

Git says "1 file changed, 0 insertions(+), 0 deletions(-)"

我刚刚在我的存储库中创建了一个有 9 行的 HTML 文件,我使用了 "git commit -m" 命令,但 git 说,“1 个文件已更改,0 个插入 (+), 0 次删除(-)".

我期望输出“1 个文件已更改,9 个插入 (+),0 个删除 (-)”,因为我创建了一个包含 9 行的文件。

在提交新文件之前,您需要使用

将其添加到"index"
git add <filename>

如果您不想使用 git addgit commit 两个命令,那么您可以使用这个(对于现有文件)

git commit -a -m 'your commit message'

根据 git 文档,将 -a 选项添加到 git 提交命令会使 Git 自动暂存每个 已跟踪的文件 在提交之前,让您跳过 git 添加部分。

对于新文件,您需要使用 git add

明确添加它

可能是您在 powershell window 本身中创建了文件(例如 echo randomtext > random.txt)。尝试手动创建!