Keystion的小博客

【转】git add -A 和 git add . 的区别

Ps:原文时间 2016-09-10 13:30

实践

git add -Agit add .git add -u在功能上看似很相近,但还是存在一点差别

  • git add .:他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
  • git add -u:他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)
  • git add -A:是上面两个功能的合集(git add --all的缩写)

下面是具体操作例子,方便更好的理解(Git version 1.x):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 -A:提交所有变化
  • git add -u:提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
  • git add .:提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件

git版本不同会有所区别:

Git Version 1.x:

New
Files
Modified
Files
Deleted
files
Description
git add -A Stage All(new, modified, deleted) files
git add . Stage New and Modified files only
git add -u Stage Modified and Deleted files only

Git Version 2.x:

New
Files
Modified
Files
Deleted
files
Description
git add -A Stage All(new, modified, deleted) files
git add . Stage All(new, modified, deleted) files
git add –ignore-removal Stage New and Modified files only
git add -u Stage Modified and Deleted files only

参考:

  1. git add -A 和 git add . 的区别
Keystion wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
来一杯咖啡~
Keystion WeChat Pay

微信打赏

Keystion Alipay

支付宝打赏