git递归添加所有.tex文件

标签 git

克隆了一个绝对新鲜的裸仓库。

现在我有一个复杂的文件结构,在我的本地工作目录中复制了许多不同的文件。但现在我只想添加所有子文件夹中的所有 .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 上,最简单的解决方案如下:

  1. 启动一个powershell
  2. cd 到仓库根目录
  3. 并运行这个命令:

    ls -Include *.tex -递归 | foreach {git 添加 $_}

我认为它的作用非常简单。

关于git递归添加所有.tex文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062060/

相关文章:

python - 虽然我安装了 python-telegram-bot,但没有名为 'telegram' 的模块的错误

python - GitPython 标签排序

git - 如何将 Go 与 Bitbucket 私有(private)存储库一起使用?

Gitignore 双星模式不起作用

git - 无法克隆现有的 Gitlab 存储库

git - 如何编辑以前的 git 提交?

git - 如何推送到git子树?

ruby-on-rails - 预编译 Assets 失败 ExecJS::ProgramError: Unexpected token: operator (=) (line: 10770, col: 0, pos: 300859)

git - 如何在 github 中比较/区分 master 和 fork repo 的特定版本

php - 我可以在没有 ssh 访问权限的情况下在 PHP 中使用 shell_exec 或反引号吗?