为什么git status显示"工作目录清理"即使我添加了一个新文件

时间:2016-01-08 15:19:54

标签: git git-status git-untracked

$ 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中看到消息' working directory clean`?

谢谢

- 更新一个 -

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:-2)

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

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

所以使用

添加文件
git add abc.cpp

or

git add .

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

  

https://try.github.io