【问题标题】:Explain "-A" flag of "git add" [duplicate]解释“git add”的“-A”标志[重复]
【发布时间】:2021-01-19 05:40:26
【问题描述】:

有人可以解释git add-A 标志吗? (--all, --no-ignore-removal)

我可以在手册页中看到它是这样说的:

-A, --all, --no-ignore-removal
           Update the index not only where the working tree has a file
           matching <pathspec> but also where the index already has an entry.
           This adds, modifies, and removes index entries to match the working
           tree.

           If no <pathspec> is given when -A option is used, all files in the
           entire working tree are updated (old versions of Git used to limit
           the update to the current directory and its subdirectories).

将其翻译成简单的英语是否正确:“当您运行命令时,无论您在目录树中的哪个位置,它都会添加文件”。这样可以吗?

另外,这是否意味着“只是为了确定而一直运行git add -A .”?

【问题讨论】:

    标签: git version-control


    【解决方案1】:

    这个标志有两种不同的行为。

    当前默认的一种行为是同时进行添加和删除。例如,如果您运行rm Makefile,那么使用此选项(或没有此选项且没有--no-all),Git 将使用git add Makefile 暂存删除。这比必须为某些路径运行 git add 而为其他路径运行 git rm 更方便。

    如果您未指定要暂存的任何文件,则另一种行为是将所有文件暂存到工作树中已修改的任何位置。这相当于你所说的除了,它要求你不要指定任何路径。请注意,如果您编写 git add -A .,则不适用,因为在这种情况下,您已告诉 Git 仅暂存工作目录及其子目录。在这种情况下,-A 只有第一个行为(除非您使用的是非常旧的 Git,否则无论如何它都会有)。

    如果您的目标是在工作树中暂存所有更改,无论您身在何处,只需运行 git add -A

    【讨论】:

    • 这是完美的。非常感谢!这是手册页中应该说明的内容。
    猜你喜欢
    • 2018-07-09
    • 2020-02-13
    • 2016-11-06
    • 2021-08-29
    • 2013-07-17
    • 2010-10-09
    相关资源
    最近更新 更多