Git commit -a "untracked files"?

GitGit Commit

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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"

Solution 3 - Git

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"

Solution 4 - Git

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

Solution 5 - Git

  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

Solution 6 - Git

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 https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository">Recording Changes to the Repository in the https://git-scm.com/book/en/v2">Progit</a> 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'.

Solution 7 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionxjq233p_1View Question on Stackoverflow
Solution 1 - Gitcoding_idiotView Answer on Stackoverflow
Solution 2 - GitzengrView Answer on Stackoverflow
Solution 3 - GitTravis DellyView Answer on Stackoverflow
Solution 4 - GitAliFurkanView Answer on Stackoverflow
Solution 5 - GitMohamadView Answer on Stackoverflow
Solution 6 - GitsateeshView Answer on Stackoverflow
Solution 7 - GitecoView Answer on Stackoverflow