为什么我添加了一个新文件后,git status 显示“工作目录干净”?

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)

3
git status 命令简单地列出当前工作目录下 Git 仓库中的更改情况,不带 -b 参数。 - Makoto
git status显示了未跟踪的文件。 - q0987
2个回答

1

命令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

-2

实际上,abc.cpp是一个新文件。由于它还没有被提交到Git中,你所做的任何更改都只会被跟踪为一个新文件。

一旦你添加了该文件并提交,Git将跟踪这些更改。

因此,请使用以下命令添加该文件:

git add abc.cpp

or

git add .

这样git就可以跟踪文件abc.cpp的更改。

您可以在此处尝试所有基本命令的在线练习。

https://try.github.io


这并没有回答他的问题:通常未跟踪的文件应该会显示出来(如果它不在gitignore中),但它没有...证据就是他编辑后的问题:仅使用git status;该文件会显示出来... - Chris Maes
@ChrisMaes 你可以看到他的更新答案,它显示文件为“未跟踪状态”,希望你能看到文件的状态。 - Viswanath Lekshmanan
在他的问题更新中,它显示为未跟踪,没问题。但他的问题不是“为什么这个文件显示为未跟踪”,而是“为什么我在git中仍然看到消息'工作目录干净'?” - Chris Maes
你提供的信息并不是错误的,只是它不是这个问题的答案。 - Chris Maes
@ChrisMaes 为什么我在 Git 中仍然看到“工作目录干净”的消息?这是我的回答。Git 没有跟踪新创建的文件,因为它没有被添加。您可以在此处检查。您刚刚用复杂的话语回答了这个问题,而不是简单明了。http://programmers.stackexchange.com/questions/69178/what-is-the-benefit-of-gits-two-stage-commit-process-staging - Viswanath Lekshmanan
你说你仍然看到消息“工作目录干净”;你使用了哪个命令?如果你只是像我在上面的答案中解释的那样使用git status,那么你应该会看到未跟踪的文件(如果你有的话)。 - Chris Maes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接