J
J
Jonathan Rosewood2014-07-01 11:16:17
git
Jonathan Rosewood, 2014-07-01 11:16:17

How to ignore everything but individual files and directories in .gitignore?

The goal is to prevent Git'om from tracking all files in the repository, except for specific files and the contents of subdirectories.
First non-working version:

# Exclude all
*

# Include files
!/foo/bar.xml

# Include directories
!/foo/bar/*

It would seem that in theory everything is correct, but it was not there.
First working version:
# Exclude all
*

# Track directories, but not the contents
!/foo/
/foo/*
!/foo/bar/
/foo/bar/*

# Include files
!/foo/bar.xml

# Include directories
!/foo/bar/*

But something tells me that there is a more concise solution, in fact, I turned here for it.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iamnothing, 2014-07-01
@Jonathan_Rosewood

As already mentioned, you can’t just add a directory to git. No matter how hard you try. If it is vital for you to have some directory under version control, then create in each directory you need (even if it is not empty, but not a single file from it was added to the git repository) a file (it can be empty) with any name - usually add .gitkeep files. And add this file to git.

D
DancingOnWater, 2014-07-01
@DancingOnWater

As an option to add files via git add

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question