Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With an initial commit, is "add ." and "add *" synonymous?

Tags:

git

Will git add . and git add * accomplish exactly the same things?

like image 947
johnbakers Avatar asked Dec 16 '22 13:12

johnbakers


1 Answers

No it will not.

* is a glob pattern, and will not match files which begin with a .

For example, let this be the current directory and I have 2 new files to add foo and .bar

$ ls -l

-rw-r--r-- 1 me users     0 Mar  7 19:31 foo
-rw-r--r-- 1 me users     0 Mar  7 19:31 .bar

When I run git add *:

$ git add *

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   foo
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .bar

Instead if I run git add .

$ git add .

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   .bar
#   new file:   foo
#

BTW using git add * .* would produce incorrect results, if you want to add only all the files under a particular directory you're in.

Let us consider this case, I've 6 new files:

foo
.bar
mydir/abc
mydir/.def
mydir2/newfile1
mydir2/newfile2

If I'm in mydir and run git add . git adds only the following files:

mydir/abc
mydir/.def

Instead if you run the command git add * .*, git adds the files in mydir in addition to any changes present one directory level above since .* glob pattern also matches ../. In other words, the following files will be added:

foo
.bar
mydir/abc
mydir/.def
mydir2/newfile1
mydir2/newfile2
like image 170
Tuxdude Avatar answered Dec 27 '22 05:12

Tuxdude