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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:44:31  来源:igfitidea点击:

Git add not adding files

gitgit-commitgit-add

提问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 /configdirectory. Whoops! #noobmistake

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

回答by opqdonut

The -aflag to git commitoverwrites 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 commitwhen you have used git add. The command git commit -ais for when you want to commit every change in the repository but can't bother to git addthem.

经验法则是使用简单的git commit,当你使用了git add。该命令git commit -a适用于您想提交存储库中的每个更改但又不想理会git add它们的情况。

PS. git add -Ais useful: it adds all non-ignored new files in your working tree

附注。git add -A很有用:它会在您的工作树中添加所有未被忽略的新文件