为什么 git 状态显示 "working directory clean" 即使我添加了一个新文件

why git status shows "working directory clean" even after I add a new file

$ git --version
git version 2.5.3

$ git branch
* feature/branchABC

$ git status -b branchABC
On branch feature/branchABC
Your branch is up-to-date with 'origin/feature/branchABC'.
nothing to commit, working directory clean

$ echo "abc" > abc.cpp

$ git status -b branchABC
On branch feature/branchABC
Your branch is up-to-date with 'origin/feature/branchABC'.
nothing to commit, working directory clean

问题> 我在当前文件夹中添加了一个新文件 abc.cpp 后,为什么我仍然在 git 中看到消息“工作目录清理”?

谢谢

--更新一--

$ git status
On branch feature/branchABC
Your branch is up-to-date with 'origin/feature/branchABC'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        abc.cpp

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

实际上abc.cpp是一个新文件。因为它没有提交到 git。您所做的任何更改仅作为新文件进行跟踪。

添加文件并提交后,git 将跟踪更改。

所以添加文件使用

git add abc.cpp

or

git add .

这样 git 将跟踪文件 abc.cpp 的更改。 您可以在此处尝试所有基本命令的在线练习

https://try.github.io

命令git status不需要参数。您提供的参数 branchABCgit-status 解释为路径。因此 git 检查名为 branchABC 的文件或目录的状态。解决方案:只需使用以下命令之一:

git status
git status -b

git-status 手册页中:git status [<options>...] [--] [<pathspec>...],并且由于 branchABC 不是有效选项;它被解释为 pathspec。我同意 git 可能会发出警告,指出没有任何匹配路径 branchABC...

我在本地测试过这个。

$ git status
# On branch test
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       spec/a
#       src/a

$ git status src
# On branch test
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       src/a

$ git status non-existing-path
# On branch test
nothing to commit, working directory clean