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

问题描述

我正在学习使用 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”标志应该将所有内容添加到暂存并提交。

我错过了什么? 谢谢!

解决方法

由于test.rb文件还没有被git跟踪,需要添加 首先使用 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.