Git add not adding files
Solution 1
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
Solution 2
The -a
flag to git commit
overwrites your staging area ("index"). Look at what the man page says:
-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.
PS. git add -A
is useful: it adds all non-ignored new files in your working tree
user200081
Updated on July 24, 2020Comments
-
user200081 over 3 years
when I try to git add my files, I typed
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:
# 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.
-
meawoppl about 10 yearsGit works from anywhere in the git working tree. . .
-
Kyle Carlson about 10 years@meawoppl It never has for me before, but I appreciate the downvote!
-
Cedric Reichenbach about 10 years@meawoppl No. Git theoretically works from everywhere, but
git add --all
may not! I think the reason is that it's equivalent togit add .
(stackoverflow.com/questions/572549/…), and thus only works for the current and sub-directories. Please only downvote if you have well-funded knowledge on the subject... -
Hady Elsahar almost 10 yearssame happened with me when executing
git add -u
command thanks for the notice