git commit -a -m 给出文件未被跟踪的错误

git commit -a -m gives error for file not being tracked

我正在学习使用 git 并且正在尝试使用分支。 我创建了一个文件“test.rb”并在 'testing' 分支上提交了一个版本。

正在 'master' 我使用 git commit -a -m 'msg' 并收到此消息:

On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.rb

nothing added to commit but untracked files present (use "git add" to track)

我不明白为什么,因为“-a”标志应该将所有内容添加到暂存并提交。

我错过了什么? 谢谢!

Since the test.rb file is not yet tracked by git, you need to add it first using git add

git add test.rb
git commit -m "msg"

之后,如果您对此文件添加更改,您可以使用 -a 选项来提交您的更改

git commit -am "msg"

git 的帮助中对 -a 标志的描述也强调了这一点:

$ git commit --help
-a, --all
           Tell the command to automatically stage files that have been
           modified and deleted, but new files you have not told Git about
           are not affected.