问题描述
我在用 Git 苦苦挣扎,我似乎无法添加我的文件.我运行 ls
以显示文件在当前目录中,然后运行 git add .
然后 git status
显示没有提交".
I am struggling with Git, I can't seem to add my files. I ran ls
to show that the files are in the current directory, then ran git add .
then git status
which showed "nothing to commit".
JJ-Computer:first_app JJ$ git init
Reinitialized existing Git repository in /Users/JJ/rails_projects/first_app/.git/
JJ-Computer:first_app JJ$ ls
Diary.txt README.rdoc config.ru log tmp
Gemfile Rakefile db public vendor
Gemfile.lock app doc script
README config lib test
JJ-Computer:first_app JJ$ git add .
JJ-Computer:first_app Jenn$ git status
# On branch master
nothing to commit (working directory clean)
JJ-Computer:first_app JJ$
推荐答案
你的命令看起来是正确的(我已经这样做了很多次).
Your commands look correct (I've done them many times that way).
第一次尝试
git add --all
然后尝试git status
.我认为这不会解决它,但值得接下来尝试.
and then try git status
. I don't think that will solve it, but worth trying next.
接下来尝试查看您的 .gitignore 文件,如果您有一个(在您执行 git init
的顶级).
Next try looking at your .gitignore file, if you have one (in the top level where you did git init
).
cat .gitignore
删除导致您的文件被忽略的所有列表.例如,是否有一个只有 *
的条目?
Remove any listings there that are causing your files to be ignored. For example is there an entry with just *
?
下次尝试:
git add --force
然后尝试git status
.
如果这些都不起作用,我注意到您从 git init
输出的内容是重新初始化"而不是初始化",所以可能有些事情搞砸了.如果您刚刚初始化它并且不介意丢失历史记录,请通过删除 .git 目录重新开始:
If none of those work, I notice that your output from git init
says "reinitialized" rather than "initialized", so something may have gotten messed up. If you've just initialized it and don't mind losing history, start over by removing the .git dir:
rm -rf .git
然后重新执行上面相同的命令.如果这不起作用,则需要有关您的设置的更多信息.例如,您可能有一个全局 .gitignore 文件:~/.gitignore_global
,需要对其进行编辑(如果您不想要,则将其删除).
And then reexecute your same commands above. If that doesn't work, some more information about your setup will be required. For example, you might have a global .gitignore file: ~/.gitignore_global
that needs to edited (or removed if you don't want it).
这篇关于git 添加.->仍然是“无事可做"有新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!