0

The other day, someone told me never to use git add -A and instead use git add .

According to this SO,

In git 1.0, git add . stages new and modified only, not deleted.`

In git 2.0, git add . stages all files including deleted, similar to git add -A

Questions:

  1. In git 2.0, is there any functional difference between git add -A and git add .?

  2. If not, why was the update made in version 2 to include --ignore-removal as an option and to change the functionality of git add .

Andrew Kim
  • 3,145
  • 4
  • 22
  • 42
  • JFTR [here](https://github.com/git/git/blob/master/Documentation/RelNotes/2.0.0.txt#L106) is the relevant part of the 2.0.0 release notes. – kostix Apr 10 '18 at 16:21
  • Also JFTR [here](https://public-inbox.org/git/1362817358-24356-4-git-send-email-gitster@pobox.com/) is the patch which introduced the change, with the backgrounds for it in its commit message. – kostix Apr 10 '18 at 16:24

1 Answers1

3

For the first question, consider this example:

git: myrepo/foo $ vim 1.c
git: myrepo/foo $ vim ../bar/2.c

Now when I do git add ., only myrepo/foo/1.c will be tracked, but myrepo/bar/2.c won't be tracked. git add -A will, however, track both.

If you issue git add . in the top directory of your working tree, it makes no difference from git add -A. This doesn't hold true if you're in a subdirectory.

For question 2, I honestly don't know why. I'm running Git 2.17.0 and from the manpage (git add --help), I see this:

--no-all, --ignore-removal
       Update the index by adding new files that
       are unknown to the index and files
       modified in the working tree, but ignore
       files that have been removed from the
       working tree. This option is a no-op when
       no <pathspec> is used.

       This option is primarily to help users
       who are used to older versions of Git,
       whose "git add <pathspec>..." was a
       synonym for "git add --no-all
       <pathspec>...", i.e. ignored removed
       files.

It's good as a substitute for the functionality changed from Git 1.0.

iBug
  • 35,554
  • 7
  • 89
  • 134
  • After reading that manpage, it seems like the reason for the update was to make `git add ` more semantic? as in with no options, 'add everything!' but if you want `new` or `deleted` files to not be staged, to then pass in an option – Andrew Kim Apr 10 '18 at 02:27