Git add not adding files

24,502

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

Share:
24,502
user200081
Author by

user200081

Updated on July 24, 2020

Comments

  • user200081
    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
    meawoppl about 10 years
    Git works from anywhere in the git working tree. . .
  • Kyle Carlson
    Kyle Carlson about 10 years
    @meawoppl It never has for me before, but I appreciate the downvote!
  • Cedric Reichenbach
    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 to git 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
    Hady Elsahar almost 10 years
    same happened with me when executing git add -u command thanks for the notice