3
$ 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)
4

2 回答 2

1

该命令git status不需要参数。您提供的参数branchABC被解释git-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
于 2016-01-08T15:52:26.770 回答
-2

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

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

所以使用添加文件

git add abc.cpp

or

git add .

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

https://try.github.io

于 2016-01-08T15:37:14.553 回答