简体   繁体   English

“git add -u”和“git add -A”有什么区别?

[英]What's the difference between “git add -u” and “git add -A”?

Okay, so I was searching "How to Remove Manually Deleted files from Git" without actually doing git rm file.txt for each file when I came across " Removing multiple files from a Git repo that have already been deleted from disk ". 好的,所以当我遇到“ 从已从磁盘中删除的Git仓库中删除多个文件 ”时,我正在搜索“如何从Git中删除手动删除的文件”而不实际为每个文件执行git rm file.txt

The two most Up-Voted commands were: 两个最受欢迎的命令是:

  • git add -u
  • git add -A

Although both of them worked for me, I still can't understand the difference and the solutions on the page don't explain it either. 虽然它们都适合我,但我仍然无法理解其中的差异,并且页面上的解决方案也没有解释。 My questions are, how are they differ from each other, and what other git commands can be used to remove files that have been deleted manually from the disk? 我的问题是,它们如何彼此不同,以及可以使用哪些其他git命令来删除从磁盘手动删除的文件?

Brief Answer: 简要回答:

git add -A is equal to git add . git add -A 等于 git add . + git add -u + git add -u


Explanation: 说明:

When you do a " git add . ", it adds all files (existing, modified and new) to the staging area but it does not remove files that have been deleted from the disk. 当您执行“ git add . ”时,它会将所有文件 (现有的,已修改的和新的)添加到暂存区域,但不会删除已从磁盘中删除的文件。

" git add -u " only adds currently tracked files (which have been modified) to the staging area and also checks if they have been deleted (if yes, they are removed from staging area). git add -u ”仅将当前跟踪的文件(已修改)添加到暂存区域,并检查它们是否已被删除(如果是,则从暂存区域中删除它们)。 This means that it does not stage new files. 这意味着它不会暂存新文件。

Doing " git add -A " performs both of these steps, that is, stages your entire directory as it is. 执行“ git add -A ”会执行这两个步骤,即按原样分阶段整个目录。


Summary: 摘要:

  • git add -A : Stages Everything git add -A :Stages Everything
  • git add -u : Stages only Modified Files git add -u :仅git add -u 修改的文件
  • git add . : Stages everything, without Deleted Files :暂存一切,没有删除文件

Read the Documentation for more. 阅读文档了解更多信息。

git add -A will track new, modified and deleted files git add -A将跟踪新的,修改的和删除的文件

git add -u will track modified and deleted files git add -u将跟踪修改和删除的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM