tags:

views:

143

answers:

2

I'm a bit new to git, and I fail to understand why git commit -a only stages changed and deleted files but not new files.

Can anyone explain why is it like this, and why there is no other commit flag to enable adding files and committing in one command?

BTW, hg commit -A adds both new and deleted files to the commit

+6  A: 

Git is about tracking changes. It relies on you to tell it which files are important enough to track. You can achieve the desired affect like so:

git add . ;git commit -a

Make sure your .gitignore file is updated.

Kelly French
Yeah. This allows you to keep various files that you don't want to track around in the repository, and only add what you are certain you want to track.
Tchalvak
the -a is redundant if done in the root of the repository. basically the questioner needs
xenoterracide
No, `-a` is not redundant. It ensures that deletions are also staged.
Charles Bailey
I want to tell git, I just want to tell it as part of the commit command, and not with a separate add command.
splintor
Options: 1) combine the commands into a script and use it instead of the base commit. 2) submit a feature request. 3) checkout the source and add the feature yourself.
Kelly French
Thanks for listing my options. I'm still interested in the main reason it doesn't yet exist. Am I the only one missing it? I think it is even more important for newbies tutorial - "here, you see - I edited a file, and now in one command I tell git to see what was changed and add commit it to the repository.". I know I can write a script to do it, but that's a bad option when writing a tutorial, or showing someone how easy and comfortable git is. I'll try to look into submitting a request.
splintor
It's dangerous to automatically add untracked files because quite often you end up with files lying around that you don't want to get added to the repository. Build results, random OS files like Thumbs.db, etc.
Mike Weller
But the option does exist in git add -A. I just want to have the same option in git commit, for cases I know what I'm doing.
splintor
+1  A: 

Kelly is correct but I think another factor is that so many people expect that behavior because CVS, Subversion, and most other tools do it that way.

If Git committed new files, you might notice that you had committed .o files long ago and even worse they might harm the build.

jhs
I don't want it to be the default, but I want it to let me do it. I can do git add ., so why not allowing me to do it as part of the git commit command?
splintor