Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "git add -A" and "git add ."

Tags:

git

git-add

The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?

like image 286
cmcginty Avatar asked Feb 21 '09 06:02

cmcginty


People also ask

What's the difference between git add and git add a?

Git add sends all files from the untracked area to the stage area. Git add is more like to be used in big projects where small changes are used to be made. Git add -a, all the untracked files to the staging area.

What is git add a?

In review, git add is the first command in a chain of operations that directs Git to "save" a snapshot of the current project state, into the commit history. When used on its own, git add will promote pending changes from the working directory to the staging area.

Does git add add untracked files?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.

Should I use git add?

The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything. Sometimes, git add can have a reputation for being an unnecessary step in development.


2 Answers

This answer only applies to Git version 1.x. For Git version 2.x, see other answers.


Summary:

  • git add -A stages all changes

  • git add . stages new files and modifications, without deletions (on the current directory and its subdirectories).

  • git add -u stages modifications and deletions, without new files


Detail:

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 
like image 59
CB Bailey Avatar answered Oct 03 '22 08:10

CB Bailey


Git Version 1.x

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ Stage new and modified files only in current folder
git add -u ✔️ ✔️ Stage modified and deleted files only

Git Version 2.x

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files in current folder
git add --ignore-removal . ✔️ ✔️ Stage new and modified files only
git add -u ✔️ ✔️ Stage modified and deleted files only

Long-form flags:

  • git add -A is equivalent to git add --all
  • git add -u is equivalent to git add --update

Further reading:

  • Git for beginners: The definitive practical guide
  • Resources to learn Git
  • Learn Git Branching
  • Explain Git With D3
like image 41
Developer Avatar answered Oct 03 '22 08:10

Developer