12

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.

user200081
  • 563
  • 2
  • 12
  • 24

2 Answers2

25

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

Kyle Carlson
  • 7,967
  • 5
  • 35
  • 43
  • 3
    Git works from anywhere in the git working tree. . . – meawoppl Oct 24 '13 at 19:21
  • 2
    @meawoppl It never has for me before, but I appreciate the downvote! – Kyle Carlson Oct 24 '13 at 21:27
  • 3
    @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 .` (http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add), and thus only works for the current and sub-directories. Please only downvote if you have well-funded knowledge on the subject... – Cedric Reichenbach Oct 30 '13 at 00:33
  • 1
    same happened with me when executing `git add -u` command thanks for the notice – Hady Elsahar Dec 10 '13 at 01:29
9

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

opqdonut
  • 5,119
  • 22
  • 25