125

When I do a git commit -a, I am seeing the following:

  # Please enter the commit message for your changes. Lines starting
  # with '#' will be ignored, and an empty message aborts the commit.
  # On branch better_tag_show
  # Changes to be committed:
  #   (use "git reset HEAD <file>..." to unstage)
  #
  # modified:   ../assets/stylesheets/application.css
  # modified:   ../views/pages/home.html.erb
  # modified:   ../views/tags/show.html.erb
  # modified:   ../../db/seeds.rb
  #
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  # ../assets/stylesheets/
  # ../views/pages/

What does those untracked files mean? All the changes have been indeed tracked. I don't understand why git is warning me about untracked files here.

EDIT:

Ok I see a lot of confused replies. This is what happens after I git commit -a this.

# On branch master
nothing to commit (working directory clean)

As you can see, there is NOTHING other than those four files that had changes applied.

My question should be rephrased as follows: Why is git warning me about untracked files when all of the changes in this commit has been tracked?

In other words, is the untracked warning in the git commit message unnecessary?

one noa
  • 345
  • 1
  • 3
  • 10
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
  • 2
    `(use "git add ..." to include in what will be committed)` – zengr Dec 12 '11 at 06:13
  • 1
    zengr that is not necessary because git commit -a will commit all changes to files that have been tracked. – xjq233p_1 Dec 12 '11 at 06:30
  • 4
    It *is* necessary when the files have never been `add`ed till now. From the docs for `-a` : *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**.* – Noufal Ibrahim Dec 12 '11 at 06:37
  • Why do you say git is 'warning' you ? As I see it the 'untracked' files message is informational. It is for you to see if those files need to be managed and act accordingly. – sateesh Dec 12 '11 at 08:28
  • @sateesh Well whatever you want to call it I still don't think this is really helpful at all. How is this informative? What am I supposed to do? Did you read my post on the "EDIT" section where I wrote there is no modification on any other file except for those listed above? If you find this informative, it's equivalent to me telling you that any random folder on your repo tree won't be tracked when there is nothing to worry about. – xjq233p_1 Dec 12 '11 at 08:34
  • `The problem isn't that Git is to hard, it's that smart developers are impatient and have exactly zero tolerance for unexpected behavior in their tools.` : http://teddziuba.com/2010/08/too-smart-for-git.html – zengr Dec 12 '11 at 22:03
  • Do you know about `.gitignore` ? You probably need such a file! – Basile Starynkevitch Sep 19 '14 at 11:12
  • 0 Make sure you're in the right directory (repository main folder) in your local git so it can find .git folder configuration before you commit or add files. – eco Sep 04 '19 at 20:20
  • The warning is unnecessary, but it just lets you know that `git commit -a` doesn't add untracked files. Apparently people are getting tripped up by this, hence the warning/info? – SO_fix_the_vote_sorting_bug Feb 22 '22 at 23:09

7 Answers7

130

For others having the same problem, try running

git add . which will add all files of the current directory to track (including untracked) and then use

git commit -a to commit all tracked files.

As suggested by @Pacerier, one liner that does the same thing is

git add -A

Legends
  • 21,202
  • 16
  • 97
  • 123
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • 9
    `git commit -a` will commit all tracked files, not track untracked files. `git add .` will track untracked files in the current directory. `git add -a` will track all untracked files. – here Sep 18 '14 at 19:03
  • 1
    @matteo it's `git add -A`, not `git commit -A` . As far as I can tell, there is no switch you can pass to `git commit` that includes untracked files. – Len Feb 07 '18 at 05:28
  • 1
    -a seems to be deprecated for just A now. Thank you, all the same. :) – tcratius Sep 14 '18 at 09:38
  • For further insight on those commands, you can check: https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add – Onat Korucu Jun 04 '20 at 06:58
  • It's worth mentioning that `git add .` won't add any files you've manually specified in your `.gitignore` file, which means you can finely control which things are (not) added automatically with `git add .`. – aggregate1166877 Nov 20 '22 at 22:44
37

git commit -am "msg" is not same as git add file and git commit -m "msg"

If you have some files which were never added to git tracking you still need to do git add file

The “git commit -a” command is a shortcut to a two-step process. After you modify a file that is already known by the repo, you still have to tell the repo, “Hey! I want to add this to the staged files and eventually commit it to you.” That is done by issuing the “git add” command. “git commit -a” is staging the file and committing it in one step.

Source: "git commit -a" and "git add"

zengr
  • 38,346
  • 37
  • 130
  • 192
  • but , as you said git commit -a = git add . + git commit why wouldn't it auto-add the file to the tracking area??.... – Johnny Dec 11 '18 at 08:28
  • 1
    @Johnny: `git commit -a` is not equal to `git add .` + `git commit`. The `git add` step adds *only the files which are listed as modified* in your `git status`, not everything in the current directory. – Soren Bjornstad Oct 22 '19 at 14:05
  • Yeah, I discovered that today! – KansaiRobot May 14 '20 at 12:29
25

You should type into the command line

git add --all

This will commit all untracked files

Edit:

After staging your files they are ready for commit so your next command should be

git commit -am "Your commit message"
Travis Delly
  • 1,194
  • 2
  • 11
  • 20
17

If you are having problems with untracked files, this 3-line script will help you.

git rm -r --cached .
git add -A
git commit -am 'fix'

Then just git push

AliFurkan
  • 487
  • 5
  • 11
9
  1. First you need to add all untracked files. Use this command line:

    git add *

  2. Then commit using this command line :

    git commit -a

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
Mohamad
  • 91
  • 1
  • 3
7

As the name suggests 'untracked files' are the files which are not being tracked by git. They are not in your staging area, and were not part of any previous commits. If you want them to be versioned (or to be managed by git) you can do so by telling 'git' by using 'git add'. Check this chapter Recording Changes to the Repository in the Progit book which uses a nice visual to provide a good explanation about recording changes to git repo and also explaining the terms 'tracked' and 'untracked'.

sateesh
  • 27,947
  • 7
  • 36
  • 45
  • 1
    +1 for the reference to progit. please update the URL to v2 https://git-scm.com/book/en/v2 and https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository – stefan123t Nov 17 '20 at 13:05
0

Make sure you're in the right directory (repository main folder) in your local git so it can find .git folder configuration before you commit or add files.

eco
  • 1,254
  • 1
  • 12
  • 22