“git add -A"之间的区别和“git add". [英] Difference between "git add -A" and "git add ."

查看:50
本文介绍了“git add -A"之间的区别和“git add".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令 git add [--all|-A] 似乎与 git add . 相同.这样对吗?如果不是,它们有何不同?

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

推荐答案

此答案仅适用于 Git 1.x 版.对于 Git 版本 2.x,请参阅其他答案.

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

总结:

  • git add -A 阶段 所有更改

git add . 暂存新文件和修改,不删除(在当前目录及其子目录上).

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

git add -u 阶段修改和删除,没有新文件

细节:

git add -A 等价于 git add .;git add -u.

关于 git add . 的重点是它查看工作树并将所有这些路径添加到暂存更改中,如果它们已更改或为新的且未被忽略,则不会暂存任何rm"操作.

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 查看所有已经 跟踪的文件,并暂存对这些文件的更改(如果它们不同或已被删除).它不会添加任何新文件,只会对已跟踪的文件进行暂存更改.

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 是完成这两个操作的便捷快捷方式.

git add -A is a handy shortcut for doing both of those.

您可以使用类似的方法测试差异(请注意,对于 Git 版本 2.x,您的 git add . git status will强>有所不同):

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

这篇关于“git add -A"之间的区别和“git add".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆