克隆了一个绝对新鲜的裸仓库。
现在我有一个复杂的文件结构,在我的本地工作目录中复制了许多不同的文件。但现在我只想添加所有子文件夹中的所有 .tex 文件。但以下内容不起作用:
git add *.tex #error-message: fatal: pathspec '*.tex' did not match any files
git add /*tex #error-message: fatal: C:/Program Files (x86)/Git/*.tex: 'C:/Program Files(x86)/Git/*.tex' is outside repository
在 Windows 机器上使用 git 版本 1.8.5.2.msysgit.0。
如何让它工作?
更新
git add **/*.tex
运行良好。
另一种方法:
如何调整 .gitignore 文件,使其忽略除 .tex 文件以外的所有内容?我在我的 .gitignore 文件中尝试了以下内容,然后创建了一个 git add .
但它没有用。
#Ignore all files
*
#except
!**/*.tex
第二次更新
让它与以下 .gitignore 文件一起工作:
#Ignore all files
*
#except
!*/
!.gitignore
!*.tex
最佳答案
正如您所写的,您在 Windows 上,最简单的解决方案如下:
- 启动一个powershell
- cd 到仓库根目录
并运行这个命令:
ls -Include *.tex -递归 | foreach {git 添加 $_}
我认为它的作用非常简单。
关于git递归添加所有.tex文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062060/