Usually, these operations can be used to do git add
rapidly.
git add -A
git add .
git add -u
But there are some minor differences:
git add -A
stages all changes.
git add .
stages new files and modifications, without deletions.
git add -u
stages modifications and deletions, without new files.
So git add -A
is equivalent to git add .; git add -u
.
-
git add .
looks at the working tree and adds all those paths to the staged changes if they are either changes or new and not ignored, it does not stage anyrm
actions. -
git add -u
looks at 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 new files, it only stages changes to already tracked files. -
git add -A
is a shortcut for doing both of these actions.
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
git add -u
is useful after editing README.md
with a text editor. Some editors may do backup automatically after editing some files with the editor.
For instance:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md.bak
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u // Will stage the already staged file README.md changes, and ignore the unstaged file README.md.bak changes
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md.bak
Refer to here.