tags:

views:

81

answers:

3

Is it redundant to run git add . and then git commit -am "commit message"?

Can I just run git add . and then git commit -m "commit message" or, alternatively, just git commit -am "commit message"?

+2  A: 

Git add + git commit -m will just commit those files you've added (new and previously tracked), but git commit -am will commit all changes on tracked files, but it doesn't add new files.

Tuminoid
+1  A: 

The -a switch tells git to stage the modified files for adding - it stands for 'all' not 'add'. If you wan't the content in a new file to be added to git then you must add it using git add before you commit it.

If you have already done a git add . then it has already added all files in the current directory i.e. both new and modified files. Hence you don't need a -a switch to stage content again. So you can rightly just follow it up with a git -m "msg"

kashif
+2  A: 

I think some of the previous answers did not see the period after git add (your original question and some of the answers have since been edited to make the period more clear).

git add . will add all files in the current directory (and any subdirectories) to the index (except those being ignored by .gitignore).

The -a option to git commit will include all changes to files that are already being tracked by git, even if those changes have not been added to the index yet.

Consequently, if all of the files are already being tracked by git, then the two approaches have the same effect. On the other hand, if new files have been created, then git add .; git commit will add them to the repository, while git commit -a will not.

git add .; git commit -a is indeed redundant. All changes have already been added to the index, so the -a does nothing.

Daniel Stutzbach
You just said what I said with more words. When someone says `git add` it means they add files they want with it, let it be with . or a list of files. The difference is clear anyways, -am will not add any new files.
Tuminoid