当使用带有文件模式的"git add"时,它只递归地添加未跟踪的文件,并忽略已更改的文件,除非它们在当前文件夹中.
例:
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: level1/test1.txt
# modified: level1/level2/test1.txt
#
# Untracked files:
# (use "git add <file>..." to incldude in what will be committed)
#
# level1/test2.txt
# level1/level2/test2.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git add level1\*.txt
$ git status
# On branch master
# Changes to be committed:
# new file: level1/level2/test2.txt
# new file: level1/test2.txt
#
# Changed but not updated:
# modified: level1/level2/test1.txt
# modified: level1/test1.txt
#
Run Code Online (Sandbox Code Playgroud)
执行后git add level1\*.txt,添加了未跟踪(test2.txt)文件,但未添加修改后的(test1.txt)文件.我已尝试使用-u选项,转义并且不转义星号等,但似乎没有任何东西能够添加匹配模式的所有文件,无论它们是否被跟踪.
当然在这个例子中我可以用-A添加所有文件,但请记住这只是为了这个问题的目的,实际上会有更多的文件,我不想将它们全部添加,并且层次结构是一些更深的文件夹.添加跟踪文件的唯一方法是引用或编写整个模式,文件名除外:git add level1**.txtOR git add level1/level2/*.txt.
在git add文档中:这里说文件模式应该以递归方式工作,并且没有说明跟踪或未跟踪文件的任何内容,它甚至给出了示例.
我正在使用msysgit,但我已经在Windows和Linux上测试了这个以防万一.
我只是想知道.我是否正确地解释了文档(因为我认为它应该基于它应该工作的文档)或者它是如何工作的?这对我来说没有意义.
好吧,这个问题或许也有答案了。
不,这似乎根本不是正确的行为。git add <filepattern>应该相当于git add file1 file2...,其中这些是与模式匹配的文件 - 但这不是这里发生的情况。