【问题标题】:Git add not adding filesGit添加不添加文件
【发布时间】:2012-10-31 14:55:33
【问题描述】:

当我尝试 git add 我的文件时,我输入了

git add <insert file names here>

这工作正常。但是,当我尝试做

git commit -a

我的 git 存储库告诉我它是空的。输出的是:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed) 
#
<insert name of files here>

nothing added to commit but untracked files present (use "git add" to track)

可能有人知道这个问题的解决方案吗?谢谢。

【问题讨论】:

  • 它也可能已经是一个被跟踪的文件。

标签: git git-commit git-add


【解决方案1】:

git commit-a 标志会覆盖您的暂存区域(“索引”)。看看手册页是怎么说的:

   -a, --all
       Tell the command to automatically stage files that have been modified
       and deleted, but new files you have not told git about are not
       affected.

经验法则是在使用git add 时使用普通的git commit。命令git commit -a 用于当您想提交存储库中的所有更改但又不想git add 它们时。

PS。 git add -A 很有用:它将所有未被忽略的新文件添加到您的工作树中

【讨论】:

    【解决方案2】:

    您可能还想确保您位于项目的根目录中。不久前,我在 Rails 项目中遇到了这个问题,然后意识到我在 /config 目录中。哎呀! #noobmistake

    【讨论】:

    • Git 可以在 git 工作树的任何地方工作。 . .
    • @meawoppl 这对我来说从来没有,但我很感激投票!
    • @meawoppl 否。理论上 Git 可以在任何地方工作,但 git add --all 可能不行!我认为原因是它相当于git add . (stackoverflow.com/questions/572549/…),因此只适用于当前目录和子目录。如果您对该主题有充足的资金支持,请仅投反对票...
    • 我在执行git add -u 命令时也发生了同样的情况,感谢您的通知
    猜你喜欢
    • 2017-07-15
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    相关资源
    最近更新 更多