Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3667170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:58:04+00:00 2026-05-19T01:58:04+00:00

I have a directory structure like this: root folder1 abc.json def.json somedir more.json folder2

  • 0

I have a directory structure like this:

  • root
    • folder1
      • abc.json
      • def.json
      • somedir
        • more.json
    • folder2
      • qwe.json
      • rty.json
    • spec
      • mock1.json
      • mock2.json
      • somedir
        • more_mocks.json

Now using a .gitignore I want to ignore all *.json files except for the ones in the spec. I don’t want to use a .gitignore in folder1 and folder2 because there are a ton of these and they will get added to a lot, and I’m sure I will forget to move the right .gitignore file in place.

In addition, there may be more nested directories with JSON files, and this rule needs to apply to all subdirectories as well.

So how do I ignore all files of a type, except for a certain subdirectory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:58:05+00:00Added an answer on May 19, 2026 at 1:58 am

    An optional prefix ! which negates the
    pattern; any matching file excluded by
    a previous pattern will become
    included again. If a negated pattern
    matches, this will override lower
    precedence patterns sources.

    https://git-scm.com/docs/gitignore

    *.json
    !spec/*.json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory structure like this: - Root - Versioned deployment folder -
I have a directory structure in svn like this: Project A branches tags trunk
I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
If i have the following directory structure: Project1/bin/debug Project2/xml/file.xml I am trying to refer
I have a large number of files in a ClearCase directory structure, and I
I am trying to determine the best directory structure of my application i have:
I have a directory of files that I'd like to append file extension to
I have a directory with 500,000 files in it. I would like to access
I have a directory with PDF files that I need to create an index
I have a directory with several subdirectories with files. How can I copy all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.