1

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.

2
  • Did you check the git manual? Commented May 13, 2016 at 4:05
  • No. I didn't check it yet. Anyway, I've cleared my query. Commented May 14, 2016 at 3:26

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Craig !
1

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.

1 Comment

Thanks a lot Mircea !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.