I understand that a .gitignore file cloaks specified files from Git's version control. I have a project (LaTeX) that generates lots of extra files (.auth, .dvi, .pdf, logs, etc) as it runs, but I don't want those to be tracked.
I'm aware that I could (maybe should) make it so all those files are put in an separate subfolder in the project, since I could then just ignore the folder.
However, is there any feasible way to keep the output files in the root of the project tree and use .gitignore to ignore everything except the files I'm tracking with Git? Something like
# Ignore everything
*
# But not these files...
script.pl
template.latex
# etc...
There are a bunch of similar questions about this, so I'll post what I wrote before:
The only way I got this to work on my machine was to do it this way:
Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.
This is from @Yarin's comment here: https://stackoverflow.com/a/5250314/1696153
These were useful topics:
I also tried
and
**/wp-content/themes/**
or
/wp-content/themes/**/*
None of that worked for me, either. Lots of trail and error!
I tried all answers as given here above, but none worked for me. After reading the gitignore documentation (here) i found out that if you exclude a folder first that the filenames in the subfolder are not being indexed. So if you use the exclamation mark afterwards to include a file, it is not found in the index and thus not being included in your git client.
That was the way to finding the solution. I started with adding exceptions for all subfolders in my folder tree to get it working, which is a hell of a job. Afterwards i was able to compact the detailed configuration to the configuration below, which is a bit contrary to the documentation..
Working .gitignore:
As result i see in my git client that only the two files inside the Pro/3rdparty/domain/modulename/ folder are being staged for the next commit, and that was exactly what i was looking for.
And if you need to whitelist several subfolders of the same folder then group the exclamation mark lines below the exclude statement like this:
Else it wont work as expected.
You can use
git config status.showUntrackedFiles no
and all untracked files will be hidden from you. Seeman git-config
for details.To exclude folder from .gitignore, the following can be done.
This will ignore all files/subfolders inside
bower_components
except for/highcharts
.Nothing worked for me so far because I was trying to add one jar from lib.
This did not worked:
This worked:
You want to use
/*
instead of*
or*/
in most casesUsing
*
is valid, but it works recursively. It won't look into directories from then on out. People recommend using!*/
to whitelist directories again, but it's actually better to blacklist the highest level folder with/*
The above code would ignore all files except for
.gitignore
,README.md
,folder/a/file.txt
,folder/a/b1/
andfolder/a/b2/
and everything contained in those last two folders. (And.DS_Store
and*.log
files would be ignored in those folders.)Obviously I could do e.g.
!/folder
or!/.gitignore
too.More info: http://git-scm.com/docs/gitignore