Git如何在.gignore中忽略所有子代和仅某些孙代

  • 本文关键字:孙代 gignore Git git gitignore
  • 更新时间 :
  • 英文 :


我有一个这样的目录结构:

/accounts/
/accounts/customer1234/
/accounts/customer1234/webhooks/
/accounts/customer1234/uploads/
/accounts/customer1234/junk.txt
/accounts/customer5678/
/accounts/customer5678/webhooks/
/accounts/customer5678/other_file.xml

我想忽略所有内容,除了"webhooks"目录中的内容。这就是我所拥有的:

# Customer information
accounts/**/*
# Don't ignore the webhooks. 
!accounts/**/webhooks/
!accounts/**/webhooks/*
!accounts/**/webhooks/**/*
!accounts/**/webhooks/**/**/*
!accounts/**/webhooks/**/**/**/*
!accounts/**/webhooks/**/**/**/**/*

问题是Git仍然忽略了整个/accounts目录和其中的所有内容。有很多客户帐户文件夹,我无法单独命名。如何忽略每个客户/webhooks目录中除所有内容外的所有内容?

服务器上安装了Git 2.3。谢谢

问题实际上是我在.gitignore文件中有一行包含以下内容:

**/*.log
**/**/*.log
**/**/**/*.log
**/**/**/**/*.log

我知道,不是很聪明。我更彻底地阅读了Git文档。这就是为什么这些文件仍然被忽略的主要原因:

以下是我最后用来取消忽略我想要的文件的行。我必须指定文件类型,因为有一堆图像混合在中

# Customer information
accounts/*/**
# Don't ignore the webooks. 
!/accounts/*/webhooks/
!/accounts/*/webhooks/*.php
!/accounts/*/webhooks/*.js
!/accounts/*/webhooks/*.css
!/accounts/*/webhooks/*.html
!/accounts/*/webhooks/**/
!/accounts/*/webhooks/**/*.php

最新更新