Git add命令未添加文件

12

当我尝试将文件添加到Git时,我输入了以下命令:

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)

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


2
它也可能已经是一个被追踪的文件。 - meawoppl
2个回答

25

同时,您可能还希望确保您在项目的根目录。我曾经在Rails项目上遇到这个问题,一直犯了一个错误,后来才意识到我在/config目录中。呃!#初学者的错误


3
Git可以在git工作树的任何位置使用... - meawoppl
2
@meawoppl,以前对我来说从未发生过,但我感谢你的负评! - Kyle Carlson
3
Git理论上可以在任何地方使用,但git add --all可能不行!我认为原因是它等同于git add .(https://dev59.com/lHRB5IYBdhLWcg3wn4UL),因此只能用于当前目录和子目录。如果您对这个问题有充分的知识,请仔细考虑再投反对票。 - Cedric Reichenbach
1
当我执行git add -u命令时,我也遇到了同样的问题,感谢您的提醒。 - Hady Elsahar

9
< p > -a 标志用于 git commit 命令,可以覆盖你的暂存区("index")。查看 man 页面的说明:

   -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 add时,请使用git commit -a命令。

PS. git add -A很有用:它会添加工作树中所有非被忽略的新文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接