Difference between "git add -A" and "git add ."
git add [--all|-A] appears to be identical to
git add .. Is this correct? If not, how do they differ?
This answer only applies to Git version 1.x. For Git version 2.x, see other answers.
git add -Astages all changes
git add .stages new files and modifications, without deletions
git add -ustages modifications and deletions, without new files
git add -A is equivalent to
git add .; git add -u.
The important point about
git add . is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.
git add -u looks at all the already tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.
git add -A is a handy shortcut for doing both of those.
You can test the differences out with something like this (note that for Git version 2.x your output for
git add .
git status will be different):
git init echo Change me > change-me echo Delete me > delete-me git add change-me delete-me git commit -m initial echo OK >> change-me rm delete-me echo Add me > add-me git status # Changed but not updated: # modified: change-me # deleted: delete-me # Untracked files: # add-me git add . git status # Changes to be committed: # new file: add-me # modified: change-me # Changed but not updated: # deleted: delete-me git reset git add -u git status # Changes to be committed: # modified: change-me # deleted: delete-me # Untracked files: # add-me git reset git add -A git status # Changes to be committed: # new file: add-me # modified: change-me # deleted: delete-me
Read more... Read less...
Here is a table for quick understanding:
Git Version 1.x:
Git Version 2.x:
git add -Ais equivalent to
git add --all
git add -uis equivalent to
git add --update
git add <path>is the same as "
git add -A <path>" now, so that "
git add dir/" will notice paths you removed from the directory and record the removal.
In older versions of Git, "
git add <path>" ignored removals.
You can say "
git add --ignore-removal <path>" to add only added or modified paths in
<path>, if you really want to.
git add -A is like
git add :/ (add everything from top git repo folder).
Note that git 2.7 (Nov. 2015) will allow you to add a folder named "
See commit 29abb33 (25 Oct 2015) by Junio C Hamano (
Note that starting git 2.0 (Q1 or Q2 2014), when talking about
git add . (current path within the working tree), you must use '
.' in the other
git add commands as well.
git add -A ." is equivalent to "
git add .; git add -u ."
(Note the extra '
git add -A and
git add -u)
git add -A or
git add -u would operate (starting git 2.0 only) on the entire working tree, and not just on the current path.
Those commands will operate on the entire tree in Git 2.0 for consistency with "
git commit -a" and other commands. Because there will be no mechanism to make "
git add -u" behave as if "
git add -u .", it is important for those who are used to "
git add -u" (without pathspec) updating the index only for paths in the current subdirectory to start training their fingers to explicitly say "
git add -u ." when they mean it before Git 2.0 comes.
A warning is issued when these commands are run without a pathspec and when you have local changes outside the current directory, because the behaviour in Git 2.0 will be different from today's version in such a situation.
From Charles' instructions, after testing my proposed understanding would be as follows:
# For the next commit $ git add . # Add only files created/modified to the index and not those deleted $ git add -u # Add only files deleted/modified to the index and not those created $ git add -A # Do both operations at once, add to all files to the index
This blog post might also be helpful to understand in what situation those commands may be applied: Removing Deleted Files from your Git Working Directory.
-Ais now the default
- The old behavior is now available with
git add -uand
git add -Ain a subdirectory without paths on the command line operate on the entire tree.
So for Git 2 the answer is:
git add .and
git add -A .add new/modified/deleted files in the current directory
git add --ignore-removal .adds new/modified files in the current directory
git add -u .adds modified/deleted files in the current directory
- Without the dot, add all files in the project regardless of the current directory.
A more distilled quick answer:
Does both below (same as git add --all)
git add -A
Stages new + modified files
git add .
Stages modified + deleted files
git add -u