【发布时间】:2012-05-04 03:28:08
【问题描述】:
当我使用命令 git add -u . 时,git 仍然不会更新未跟踪的文件。
仅当我通过路径指定它们时才有效,git add -- filepath
会是什么?
【问题讨论】:
当我使用命令 git add -u . 时,git 仍然不会更新未跟踪的文件。
仅当我通过路径指定它们时才有效,git add -- filepath
会是什么?
【问题讨论】:
未跟踪文件无法更新。他们一开始就没有被跟踪。
您需要添加未跟踪的文件。要做到这一点,您最常使用:
$ git add some_untracked_file
$ # or
$ git add . # add all files
$ # or
$ git add --all # similar to -A , add all again
all 这里并不意味着每个文件,而是每个与 .gitignore 文件中的条目不匹配的文件。
来自手册页:
-u, --update Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed. If no <filepattern> is given, default to "."; in other words, update all tracked files in the current directory and its subdirectories. -A, --all Like -u, but match <filepattern> against files in the working tree in addition to the index. That means that it will find new files as well as staging modified content and removing files that are no longer in the working tree.
【讨论】:
git add . 和 git add -A 都添加了所有 untracked 文件,这些文件与 .gitignore 文件中的条目不匹配。您可以轻松地进行测试:mkdir test; cd test; touch a b c; git init; git add a; git commit -m "add a"; echo "b" > .gitignore; git add .gitignore; git commit -m "add ignore"; git add .; git commit -m "add c"; b 被忽略并且未被git add . 或git add -A 添加,因为它与 .gitignore 中的条目匹配。
参见 git 手册:
-u,--更新 仅匹配索引中的已跟踪文件而不是工作树。这意味着它永远不会 暂存新文件,但它将暂存修改后的新内容 跟踪的文件,并且它将从索引中删除文件,如果 工作树中的相应文件已被删除。
【讨论】: