Git的。更新未跟踪的文件

时间:2012-04-23 13:52:31

标签: git git-add

当我使用命令git add -u .时,git仍然不会更新未跟踪的文件 仅当我按路径指定git add -- filepath时才有效 它可能是什么?

2 个答案:

答案 0 :(得分:3)

未跟踪的文件无法更新。它们首先没有被追踪 您需要添加未跟踪的文件。最常用的方法是:

$ git add some_untracked_file
$ # or
$ git add .  # add all files
$ # or
$ git add --all # similar to -A , add all again

所有并不意味着每个文件,但每个文件都不匹配 .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.

答案 1 :(得分:2)

参见git手册:

  

-u, - 更新   仅匹配索引中的已跟踪的文件而不是工作树。这意味着它永远不会   阶段新文件,但它将阶段修改新的内容   跟踪文件,它将从索引中删除文件,如果   工作树中的相应文件已被删除。