首先,如果之前有人问过这个问题,我们深表歉意;这是一件相当困难的事情。
我想知道如何将与特定模式匹配的所有文件添加到索引中,同时仍然排除.gitignore
.
例如,我有一个包含一些 tex 代码的仓库。我保留.tex
文件以及.pdf
在版本控制下编译,同时忽略辅助文件:
$ cat .gitignore
# LaTeX auxiliary files
*.aux
*.log
*.out
我经常同时提交.tex
文件和.pdf
文件,因此我在 repo 中有以下文件:
mytexdoc.aux
mytexdoc.log
mytexdoc.out
mytexdoc.pdf
mytexdoc.tex
我想做的是能够运行git add mytexdoc.*
添加与此模式匹配的文件,但不会在.gitignore
, iemytexdoc.tex
和mytexdoc.pdf
. 但是,当我运行此命令时,会收到如下消息:
$ git add mytexdoc.*
The following paths are ignored by one of your .gitignore files:
mytexdoc.aux
mytexdoc.log
mytexdoc.out
Use -f if you really want to add them.
fatal: no files added
甚至有可能做到这一点吗?如果没有,有人知道它背后的原理吗?因为这对我来说似乎违反直觉。