2

When I type

git add *

it acts as if there were no files added, yet when I do

git status

it shows files that are unstaged. I can stage them by manually typing the name, as shown in the picture, but that takes quite a while in same cases.

My question is why, in this instance, can I not just type "git add *" to add the unstaged files, and how should I resolve this? Thank you in advance.

This image shows the behavior I am encountering https://i.stack.imgur.com/S2dxc.png

gravetii
  • 9,273
  • 9
  • 56
  • 75
Connorelsea
  • 2,308
  • 6
  • 26
  • 47

2 Answers2

5

If you want to add all files, don't use '*' (which is interpreted by the shell)

git add .

git add -u would add updated files. git add -A . combines the two.
See "What's the difference between git add . and git add -u?"
Also "Difference between “git add -A” and “git add .”":

The . indicates the command operates in the current subdirectory instead of the entire working tree.

If you want to known if a file is ignored: git check-ignore -v -- yourFile.


As explained in "What's the difference between git add * and git add ., if any?":

git add * will add all the paths that are the result of the shell expansion of * whereas git add . will tell git to add the current directory.

git add * won't add paths that begin with a . as the shell expansion of * considers these to be "hidden" paths.

torek explains in the comments why '*' fails in this particular scenario:

in this particular case, git add * becomes

git add Bootstrap afile bfile ... index.php main.js ... zfile

or some such, and git add * stops with a fatal error because you told it:

  • "don't add Bootstrap via .gitignore", and
  • "do add Bootstrap via explicit path"

It does not know which to obey, so it does nothing at all.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Alternativly use `git add -u` to add all updated files and `git add -A` to add all files, even untracked ones and deletions. +1 for `check-ignore`. – Sascha Wolf Jul 25 '14 at 07:20
  • Doing it with a period works. Can you explain more exactly what the period indicates? For example, I though the "*" added all unstaged changes. Thank you. – Connorelsea Jul 25 '14 at 07:22
  • Could someone explain the difference between the ., -u, and -a. Thanks! That would be really helpful for me. – Connorelsea Jul 25 '14 at 07:23
  • @Connorelsea `.` indicates the current dir. – gravetii Jul 25 '14 at 07:23
  • @Connorelsea I have edited the answer with links explaining the difference – VonC Jul 25 '14 at 07:25
  • The edits you made to your answer are very helpful @VonC. I will make this the accepted answer. Also, what does `git add *` do then? – Connorelsea Jul 25 '14 at 07:26
  • 1
    @Connorelsea I have edited the answer with why '*' isn't a good idea. – VonC Jul 25 '14 at 07:28
  • 1
    And, in this particular case, `git add *` becomes `git add Bootstrap afile bfile ... index.php main.js ... zfile` or some such, and `git add` stops with a fatal error because you told it "don't add `Bootstrap` via `.gitignore`, and do add `Bootstrap` via explicit path" and it does not know which command to obey, so it does nothing at all. – torek Jul 25 '14 at 07:45
  • Thanks @torek , that is a very good explanation of what is actually happening, and helped me to understand the situation at a deeper level. – Connorelsea Jul 25 '14 at 07:48
  • 1
    @Connorelsea I have edited the answer to include torek's comment – VonC Jul 25 '14 at 07:49
0

Check if you really want to ignore the directory Bootstrap/ which you say is in your .gitignore. Also, as @VonC mentioned in his answer, the correct way to add the current directory to the staging area is git add .

gravetii
  • 9,273
  • 9
  • 56
  • 75