Git添加不添加文件

时间:2012-11-12 06:48:05

标签: git git-commit git-add

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

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)

可能有人知道解决方案吗?感谢。

2 个答案:

答案 0 :(得分:16)

您可能还想确保自己位于项目的根目录中。我暂时在Rails项目上遇到了这个问题。然后意识到我在/config目录中。哎呦! #noobmistake

答案 1 :(得分:6)

-a的{​​{1}}标志会覆盖您的暂存区域(“索引”)。看一下手册页的内容:

git commit

经验法则是在使用 -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 commit。命令git add适用于您希望提交存储库中的每个更改但不能打扰git commit -a它们的时间。

PS。 git add很有用:它会在工作树中添加所有未忽略的新文件