【问题标题】:Why doesn't "git add *" add files in the root directory?为什么“git add *”不在根目录下添加文件?
【发布时间】:2014-01-25 19:31:12
【问题描述】:

编辑:执行以下步骤实际上会重现该行为。是的,该文件名为stuff.txt,并且文件名中没有以. 开头。当我执行echo * 时,它确实会打印stuff.txt

git add * 命令与git add . 大致相似,但有一个主要例外:git add * 不会在 Git 存储库的根目录中添加文件。它不会添加新文件 (??) 或修改现有文件 (M)。以下是重现所需的步骤:

mac$ mkdir myrepo
mac$ cd myrepo
mac$ git init
mac$ touch stuff.txt
mac$ git add *
fatal: no files added

mac$ git status -s
?? stuff.txt
# It looks like 'git add *' totally dropped the ball.

mac$ git add .
# Nothing prints. Success?
mac$ git status -s
A  stuff.txt
# Yes, success.

知道问题是什么吗?只要添加或修改的文件位于子目录中,git add * 就可以正常工作,例如 myrepo/mydir/。该问题仅发生在存储库顶层的文件中。

我的设置:
Mac OS X 10.9.1 小牛
Git 版本 1.8.3.4 (Apple Git-47)
我通过安装 Apple Xcode 获得了那个版本的 Git。
苹果终端版本 2.4 (326)

我应该指出,我纯粹是出于好奇。使用 git add . 是 100% 令人满意的解决方法。

【问题讨论】:

  • 这很奇怪。 *与Git无关,应该是shell扩展。
  • 文件实际上是叫stuff.txt还是它的名字以.开头?
  • @Mat:文件名实际上是stuff.txt,开头没有.

标签: macos git bash


【解决方案1】:

正如 Mat 的评论所暗示的那样,* 不匹配以 . 开头的任何内容。这就是 shell 的工作方式(与 git 无关)。您可以通过在 shell 中运行 echo * 来测试它。

要匹配点文件,您必须使用.[!.]*。 (使用echo .[!.]* 对其进行测试。)简单地使用.* 也将匹配...,您不想使用git add

【讨论】:

    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多