Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a git repository, call it myscripts/. Within myscripts/ are subdirectories perl/, python/, and ruby/. For some reason, when I edit code in one of the subdirectories, Git forgets that the subdirectory is part of the repository.

$ cd myscripts/
$ cd perl/
$ vi
$ git commit -a
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#   ./
$ git add .
$ git commit -a

I have to do this over and over, and I don't know why.

share|improve this question
I think this is how git is supposed to work. Unlike SVN you have to specify what to commit in each changeset. – Nov 22 '11 at 3:15 - no, that's incorrect. If a file/folder has been added, all changes will be tracked – Sathya Nov 22 '11 at 4:27
@Sathya, @billc.con is correct, in normal operation you must run git add to specify what to include in the commit. You can create a commit which includes all changes to tracked files using the command git commit -a, which is being used in this question. – heavyd Nov 22 '11 at 16:25
@heavyd ah you're right, I was mistaken – Sathya Nov 22 '11 at 16:35
Is a new file? If I'm not mistaken -a only adds existing files to be committed. What is the output of git status after editing file? – johnny Nov 23 '11 at 13:49

When you run git commit, Git creates a new commit with the contents of the index. The index contains the current HEAD, plus any changes you have made using git add or git rm.

However, git commit does accept the -a switch. The man page says about this switch:

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.

This means that when you run git commit -a, Git will only commit changes to files that exist in the current HEAD.

Therefore, you must run git add at least once on each file or directory you want to track:

$ cd myscripts/
$ cd perl/
$ vi
$ git add .               # Add each file in this directory to the index
$ git commit              # Commit this version of
$ vi             # Edit some more
... edit some more ...
$ git commit -a           # Commits the changes to
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .