git add 不添加文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13339397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git add not adding files
提问by user200081
when I try to git add my files, I typed
当我尝试 git add 我的文件时,我输入了
git add <insert file names here>
That works correctly. However, when I try to do
这工作正常。但是,当我尝试做
git commit -a
My git repository tells me that it's empty. What is outputted is:
我的 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)
Might anyone know the solution to this? Thanks.
可能有人知道这个问题的解决方案吗?谢谢。
回答by Kyle Carlson
And you may also want to make sure you're in the root of your project. I had that problem for a while on a Rails project a while back & then realized I was in the /config
directory. Whoops! #noobmistake
而且您可能还想确保您位于项目的根目录中。不久前,我在 Rails 项目中遇到了这个问题,然后意识到我在/config
目录中。哎呀!#noobmistake
回答by opqdonut
The -a
flag to git commit
overwrites your staging area ("index"). Look at what the man page says:
覆盖临时区域的-a
标志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.
A rule of thumb is to use a plain git commit
when you have used git add
. The command git commit -a
is for when you want to commit every change in the repository but can't bother to git add
them.
经验法则是使用简单的git commit
,当你使用了git add
。该命令git commit -a
适用于您想提交存储库中的每个更改但又不想理会git add
它们的情况。
PS. git add -A
is useful: it adds all non-ignored new files in your working tree
附注。git add -A
很有用:它会在您的工作树中添加所有未被忽略的新文件