Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 hello.pl
...
$ 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. –  billc.cn Nov 22 '11 at 3:15
    
@billc.cn - 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
1  
Is hello.pl 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

1 Answer 1

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 hello.pl
...
$ git add .               # Add each file in this directory to the index
$ git commit              # Commit this version of hello.pl
$ vi hello.pl             # Edit hello.pl some more
... edit some more ...
$ git commit -a           # Commits the changes to hello.pl
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.