如何让git忽略vendor/下的.git文件夹?

Rol*_*ser 5 git gitignore composer-php

我正在使用 Composer,为了进行开发,我想将 .git 文件夹保留在供应商目录中,这样我就可以跟踪差异等。所以我的项目结构是:

projectroot/
  .gitignore
  file1
  file2
  vendor/
    dir1/
      module1/
        .git/
        module1file1
        module1file2
        ...
    dir2/
      module2/
        .git/
        module2file1
        ...
Run Code Online (Sandbox Code Playgroud)

我想提交到 git,这些文件:

file1
file2
vendor/dir1/module1/module1file1        
vendor/dir1/module1/module1file2    
vendor/dir2/module2/module2file1        
...
Run Code Online (Sandbox Code Playgroud)

我的projectroot/.gitignore 文件应该是什么?从我尝试过的作曲家文档中

vendor/*.git
Run Code Online (Sandbox Code Playgroud)

vendor/*/.git
Run Code Online (Sandbox Code Playgroud)

但在这两种情况下, git 1.8.3 仍然想提交vendor/dir1/module1vendor/dir2/module2作为子模块,我想提交下面的文件。

在这种情况下 .gitignore 语法应该是什么?

Ali*_*man 1

我放入vendor/.gitignore 文件 - 除其他外 - 然后,如果我想编辑我用 Composer 引入的库(除非它拉入“dist”存档文件版本),我可以这样做,而且它仍然会有库 .git 目录。由于该库是它自己的存储库,因此我可以根据需要进行编辑和推送,但它仍然可以从顶级应用程序(或库)中使用。

  • 我希望将供应商文件(例如“vendor/dir1/module1/module1file1”)直接提交到主存储库,这样我就可以一眼看到通过“git diff”更改了什么。由于供应商存储库位于“/vendor”下的多个层,因此我无法通过查看“/vendor”来看到更改,并且需要手动递归到每个存储库并逐一检查它们。但也许这就是人们通常对作曲家所做的事情? (2认同)