A" and "git add ."
The command git add [--all|-A]
appears to be identical to git add .
. Is this correct? If not, how do they differ?
For Git version 2.x , see answers below too.
Summary:
git add -A
stages All
git add .
stages new and modified, without deleted
git add -u
stages modified and deleted, without new
Detail:
git add -A
is equivalent to git add .; git add -u
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
Here is table for quick understanding:
Git Version 1.x :
Git Version 2.x :
Long-form flags:
git add -A
is equivalent to git add --all
git add -u
is equivalent to git add --update
Further reading:
With Git 2.0, git add -A
is default: git add .
equals git add -A .
.
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>
" used to ignore 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
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 ( gitster
).
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.
That means:
" git add -A .
" is equivalent to " git add .; git add -u .
"
(Note the extra ' .
' for git add -A
and git add -u
)
Because 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.
链接地址: http://www.djcxy.com/p/116.html上一篇: REST API返回JSON的MIME类型是什么?
下一篇: 一个“和”git add“。