.gitignore everything but .c and .h recursively - c

I would like to ignore everything in a certain folder and its subfolders, except for .c and .h files.
Yet locally, i need other files too. Do i have to have these files, which should not be tracked, in the git-repo before or after i add the .gitignore?
And how do i do this?:
#ignore all
*
#but:
!source/**/*.c
!source/**/*.h
This is my current solution, but it does not work. But i think this also relates to the point in time, where i have to add the files, that should be ignored, but need to be there locally?
EDIT:
The problem is, i got a copy of a project, that does all kinds of makefile magic and other things, i do not even know what kind of file-types and subfolders there are (i will only work in one folder of the massive project, so i don't think, that the gitignore needs to be so exclusive) ... and i can't just commit everything, because the "lib" has to be installed i think, so everybody needs to do this on his own ...

Ignoring * means ignore everything including top-level directories. After that git doesn't even look into subdirectories. To fix that unignore directories. Your entire .gitignore should look like this:
# Ignore all
*
# Unignore directories
!*/
# Unignore source code files
!source/**/*.c
!source/**/*.h
Another approach is to ignore everything but force-add necessary files with git add -f.

The problem is that the pattern
*
excludes all directories, too. According to the gitignore documentation,
It is not possible to re-include a file if a parent directory of that file is excluded.
To make this work, then, you'll need to use make sure that directories are not ignored. The gitignore pattern format does not provide a way to distinguish between directories and regular files, so you'll need to do that manually. One possibility would be to put a .gitignore file in each that directory that reincludes all its subdirectories, but it would be easier to just reinclude all directories. These can be matched (exclusively) with a pattern that ends with a '/':
!source/**/
Also, you are right when you say
But i think this also relates to the point in time, where i have to add the files, that should be ignored
in the sense that gitignore does not apply to files that are already tracked.

Related

Conditionally ignore path from Subversion?

Is it possible to globally ignore a folder IF it is a child of a folder having a specific name? For example...
Exclude:
client/vendor
... or ...
app/vendor
But never exclude a "vendor" folder if it appears anywhere else?
I'm working on an AngularJS project and the "vendor" folder is common for client-side files. However, theoretically, it is possible that "vendor" may have another meaning in future projects and, if it does, it would generally be in another path.
The docs on this are a bit misleading (to me, anyway). It says to use the svn:ignore property but no examples anywhere show how to specify the conditional parent folder. They all appear to be manually ignoring a specific folder every time... via a command line.
Per the TortoiseSVN docs:
No Paths in Global Ignore List (Link here) You should not include
path information in your pattern. The pattern matching is intended to
be used against plain file names and folder names. If you want to
ignore all CVS folders, just add CVS to the ignore list. There is no
need to specify CVS */CVS as you did in earlier versions. If you want
to ignore all tmp folders when they exist within a prog folder but not
within a doc folder you should use the svn:ignore property instead.
There is no reliable way to achieve this using global ignore patterns.

How to achieve symbol referencing across directories in vim?

Can ctags tag symbols from a directory up in the hierarchy also or is it limited to create tags for current and sub-directories only?
Basically I'm looking for Visual Studio like symbol cross referencing it is very helpful in understanding alien source code flow.
If not Vim, then which other editor should I use?
thanks
Ctags only recurses to subdirectories. But all you have to do is run ctags -R . in your project home directory, and it will create a tags file for your whole project.
You aren't limited to specifying one tags file in Vim. This is an alternative to the other answers; you can just do something like:
set tags=tags,~/wintags,c:/path/to/moretags/etc
So you don't need to take the time regenerating a monolithic tags file when you just want to update your local tags.
Regarding the OP's comment in another answer,
yes thats correct but when i open a file say proj/dir1/def.c and press ctrl+] on a function name which is defined say in proj/dir2/abc.c, I get tag not found :(
You could also create one tags file for all of your projects at the 'proj' root:
set tags=tags;c:/path/to/proj
This will use the first file named tags that it finds as it walks up the directory hierarchy from where you are.
You can combine these two techniques to have a project-local tags file and then a "global" tags file that isn't updated as often.
Whilst it's got similar user interface for asking it to do it's thing, so you need to actually specify "go down directories", I find that cscope is a very nice tool, whcih does everything that ctags does and a bit more.
ctags (well, exctags at least) can create tags for as many directory trees you want. Simply run
exctags -R dir1 dir2 ...
Then vim knows about all the symbols you need. For example, one of the directories could be /usr/include in addition to your own source directory.
Make sure to run vim path/to/file.c from the same directory you created the tags file in.

NetBeans - replace in textfiles under a subdirectory

I have troubles with replacing file contents in my current project. I renamed a directory, and a lot of class names has been changed cause of this. A want to rename this classes with netbeans, but I cannot setup the file path pattern well.
The previous directory path was: Test/TestCase under Source Files, and the new path is Test/UnitTest. So I have to rename the TestCase word to UnitTest in my php files.
I tried with *.php, it works (of course it works...), but returns every php file in the project which contains that word, and I don't want to choose from circa half thousand files the right ones. The files of the unit test system could easily contain the TestCase word...
Tried out the following patterns, but they gave empty result:
Test\UnitTest\*.php
*Test\UnitTest\*.php
Test/UnitTest/*.php
*Test/UnitTest/*.php
Test/UnitTest/*
I have not a clue what I do wrong... I tried to search a tutorial for file search patterns but have found only regex patterns and those are definitely not what I was looking for. Can anybody help me?
Lol, I checked it again, and I realized, that I didn't notice the "scope" part last time. In that you can choose the current selection instead of the entire project. So the pattern matches only the file name, not the relative path of the file...
It was so obvious... This is an epic fail, I think I was too tired...

How can git be configured to ignore files?

There are some files we want ignored, not tracked, by git, and we are having trouble figuring out how to do that.
We have some third-party C library which is unpacked and we have it in Git. But when you configure && make it, it produces many new files. How to write .gitignore to track source files and not the new stuff. (it's not like forbidding *.o)
Edit: There are at least 12 file-types. So we would like NOT to enumerate, which type we want and which not.
Use ! to include all the types of files you need. Something like in the following example"
*
!*.c
!*.h
Explicitly specifying which files should be tracked and ignoring all others might be a solution. * says ignore everything and subsequent lines specify files and directories which should not be ignored. Wildcards are allowed.
*
!filename
!*.extension
!directory/
!/file_in_root_directory
!/directory_in_root_directory
Remember that the order matters. Putting * at the end makes all previous lines ineffective.
Take a look at man gitignore(5) and search for !. It says
Patterns have the following format:
(...)
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.
I'm not sure why you say "it's not like forbidding *.o", but I think you mean that there aren't any good patterns you can identify that apply to the generated files but not to the source files? If it's just a few things that appear (like individual built executables that often don't have any extension on Linux), you can name them explicitly in .gitignore, so they aren't a problem.
If there really are lots and lots of files that get generated by the build process that share extensions and other patterns with the source files, then just use patterns that do include your source files. You can even put * in .gitignore if it's really that bad. This will mean that no new files show up when you type git status, or get added when you use git add ., but it doesn't harm any files that are already added to the repository; git will still tell you about changes to them fine, and pick them up when you use git add .. It just puts a bit more burden on you to explicitly start tracking files that you do care about.
I would make sure the repo is clean (no changes, no untracked files), run configure && make and then put the newly untracked filed into the ignore file. Something like git status --porcelain | fgrep '??' | cut -c4- will pull them out automatically, but it would be worth some eyeball time to make sure that is correct...

mercurial .hgignore - won't ignore files

I'm trying to ignore a file in my project with .hgignore, and just can't figure it out. The file is located in app/views/patterns/_changes.erb (relative to the root of the project, where .hgignore is), and nothing I try seem to work:
#.hgignore
syntax: glob
app/views/patterns/_changes.erb
*changes.erb
public/files/* # this works
I read the .hgignore doesn't distinguish between folders and files, but can't really make it happen. Any clue? thanks.
If you just put:
_changes.erb
as an entry, that should work. It will ignore that file name, regardless of location. Note that if the file is already in the repository, it won't REMOVE it... it just won't prompt you to add it next time it sees a file with that name.
As a side note, if you want to remove a file from version control, use the command:
hg forget _changes.erb
(Note that this will remove the file from the current revision onwards. The file will always remain in past changesets -- i.e. it's not a total purge of the file.)

Resources