How to ignore an extension file in entire app except a particular folder - github

I have a requirement in my project where I need to ignore the .html file to track via git in the project however need to track any .html file in a given folder along with its sub folder.
I tried using below code to exclude to track all files from ignore_directory but it didn't worked.
*.html
!ignore_directory/*

What you have is the correct way to exclude a directory.
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor or
# operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
*.html
!ignore_directory/*
Either the path you have is incorrect or is not relative to the directory you want to exclude. It's also possible that the directory you want to exclude contains a gitignore file overriding your exclusion.
Read GitHub help on Ignoring files for a simple introduction to ignoring files and also tead the Git - gitignore documentation.

Related

Why doesn't this ignore my files recursively?

In my project's root directory there are directories like 'tools':
tools/evaluate/test/
tools/evaluate2
Under test, there are some .py and .csv files. I want to ignore all files except .py, so in my .gitignore, I have this entry:
!tools/**/*.py
I want to recursively ignore all non-python files under tools. What's wrong with that?
if the files you are trying to ignore have been already committed, you need to remove them from the staging area as well, that's done by:
git rm --cached !tools/**/*.py
check the status:
git status
add the files you want to delete to .gitignore i assume manually, i don't know of an automatic way, then finally:
git add .gitignore
git commit -m "Remove unused files"
Two parts are needed here:
# Recursively ignore everything in tools that has an extension:
**/tools/**/*.*
# Except .py files recursively in tools:
!tools/**/*.py

Github - gitignore folder doesn't exclude all directory files

I'm using Github Desktop on Windows 10. I have a .gitignore file with which I'd like to ignore everything in the directory, including all subdirectories.
What's frustrating is that most files are excluded, but I'm still getting a few random files that I cannot seem to ignore.
I have a directory, say, My Dir/Sub-dir, I want to ignore. I also want to ignore all files of extension, say, *.swf. Thus, I write this .gitignore file:
My Dir/Sub-dir
*.swf
But, when I go back to Github Desktop, I still get two files similar to the following in the list:
My Dir/Sub-dir/anotherdir/randomfile.xml
My Dir/Sub-dir/animation.swf
What's going on? Is this a bug? Or am I missing something?
EDIT:
Other alternative .gitignores I've tried are:
My*Dir/Sub-dir
*.swf
My\ Dir/Sub-dir
*.swf
My Dir/Sub-dir/
*.swf
/My Dir/Sub-dir
*.swf
EDIT:
So, I've tried the git rm --cached <file> command on my files, and it worked - until one of the files changes again. Github Desktop then once again says they need to be updated.
p.s. It may be that they somehow got indexed in the master branch, as I'm currently in a different branch. Would this cause it? And, if so, how would I eliminate these files from all branches?
To ignore all trees under specific directories, append the trailing slash to the directory:
# Ignore directory at all levels, even if the directory is nested under other directories
My Dir/Sub-dir/
# Ignore the directory only if it exists at the root of your repository
/My Dir/Sub-dir/
# Ignore the sub-directory, no matter where it appears within your repository
Sub-dir/
# Ignore all swf files
*.swf
If you are continuing to experience difficulties, your problem may be that the files you wish to ignore are already indexed by git (via the git add command). If the files are not committed yet, you can remove them from the index with git reset -- 'My Dir/Sub-dir/'. If your files have been committed, you can remove them from the index with git rm --cached <file>.
I guess the whitespace could be a problem. Try
My\ Dir/Sub-dir
or
My*Dir/Sub-dir
This could be a good reference .gitignore entire directory with whitespace in name

.gitignore that ignore all the files that have a peer with a *.in

I have some generated files from templates. Let's say I have in my repository:
foo.c.in
bar.h.in
baz.html.in
These files could be generated through a Make rule:
$(wildcard *.in): %: %.in
PYTHONPATH+=. mako-render $< > $#
I don't want to manually add each of these generated files to my .gitignore
foo.c
bar.h
baz.html
Is there a smarter way?
If those two sets of files are the only one in a given folder, you can:
ignore everything
exclude the *.in files
That is
*
!*.in
But if those files are not alone, and in multiple folders, then, as commented, your Makefile would need to generate the list of files to ignore, either in:
a dedicated .gitignore
a dedicated file specified by the configuration variable core.excludesFile

How to exclude path on the deployment in PhpStorm from .gitignore

I always need to exclude all the path defined in the .gitignore file when I synchronize the server with the deployment feature of PhpStorm.
There is a way to copy these path and exclude them without manually exclude them one by one?
I'm searching like a configuration file or somewhere to put a list of directory and files like in the .gitignore file

Removing file from .gitignore in webstorm

I was searching the web for hour now...
I can't seem to find where the gitignore file is located,and it's ruining my life. I have to remove one file from there. I'm using WebStorm 8
Any help?
.gitignore can be in any folder inside your git repository. And the patterns in .gitignore of child folder will overwrite the ones in parent folder.
It may be hidden when you use ls in your Git Bash. Just use ls -a.
From the doc:
Patterns read from a .gitignore file in the same directory as the
path, or in any parent directory, with patterns in the higher level
files (up to the toplevel of the work tree) being overridden by those
in lower level files down to the directory containing the file. These
patterns match relative to the location of the .gitignore file.