Nevil
Nevil

Reputation: 45

Difference between git add . and git commit -am "message"

I use Git instructions in this sequence:

  1. git add .
  2. git commit -m "message"

However, I learnt from some tutorial that git commit -am "message" does the same. So I began using it in projects and it worked.

But now when I use commit -am, it doesn't add to staging area and gives this output:

$ git commit -am "added files in repo"
On branch master

Initial commit

Untracked files:
        .RData
        .Rhistory
        CSV.BAT
        ExpenseCalculator.R
        GenerateCsv.class
        GenerateCsv.java
        test.csv

nothing added to commit but untracked files present

So I would like to know the concept behind using the two commands.

Upvotes: 1

Views: 274

Answers (2)

Craig Estey
Craig Estey

Reputation: 33601

git add -a [or git commit -a] means any files that have been modified [but not created] in all subdirectories of the working directory, regardless of the current directory will be staged for commit.

On the other hand, git add . means all files modified [or new files] but descending from the current directory.

So, if you have new/changed files that are not in the current directory or one of its subdirectories, these files will not be staged for commit

Upvotes: 4

Mircea
Mircea

Reputation: 10566

https://www.kernel.org/pub/software/scm/git/docs/git-commit.html

-a is "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."

The difference here is that git add also works for unknown (ie new) files.

Upvotes: 1

Related Questions