【问题标题】:why git status shows "working directory clean" even after I add a new file为什么 git status 显示“工作目录干净”即使我添加了一个新文件
【发布时间】:2016-04-13 07:56:38
【问题描述】:
$ 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)

【问题讨论】:

  • plain ol' git status 给你什么?你知道,没有-b 参数?
  • git status 确实显示了未跟踪的文件。

标签: git git-status git-untracked


【解决方案1】:

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

git status
git status -b

git-status 手册页中:git status [&lt;options&gt;...] [--] [&lt;pathspec&gt;...],因为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;文件显示...
    • @ChrisMaes 它将文件显示为untracked,您可以看到他的更新答案。希望您可以将文件视为未跟踪
    • 在更新他的问题时,它显示为未跟踪,好吧。但他的问题不是“为什么这个文件显示未跟踪”,而是why I still see the message 'working directory clean' in git?
    • 您的信息没有错,但它不是这个问题的答案。
    • @ChrisMaes 为什么我仍然在 git 中看到消息“工作目录干净”?` 这就是我的回答。 Git 没有跟踪新创建的文件,因为没有添加。你可以在这里查看。你只是用复杂而不是简单的话回答programmers.stackexchange.com/questions/69178/…
    猜你喜欢
    • 2019-04-12
    • 1970-01-01
    • 2016-09-13
    • 2021-02-12
    • 2015-02-13
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多