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

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

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

Ignore a specific file in resource directory

This is my .gitignore file:
HELP.md
tmp/
target/
!**/src/main/**
!**/src/test/**
How can I exclude only this file:
src/main/resources/application.properties
Thank you
It should be fairly easy:
HELP.md
tmp/
target/
!**/src/main/**
!**/src/test/**
src/main/resources/application.properties
should work.
In case it doesn't, as it appears to be your case1, git allows you to ignore files, but remember this is a local setting and it will not be pushed to any other repository: go to .git/info/exclude and edit the file. It works like .gitignore.
Also remember: .gitignore has an higher priority on your info/exclude (source).
1. this might be due to the fact that you have multiple .gitignore files in your directory, and thus there is overmatching of patterns.

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

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.

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

How can I efficiently get new directories with cvs?

If another developer adds a new directory to the CVS repository, I'd like my next update to bring this new directory into my working copy. Running cvs update doesn't do this. Running cvs update -d does, but it takes a helluva long time; it prints the pathname of every file in the repository and spends a little time thinking about each one. Running cvs update -d <dirname> in the new directory's parent does the job, but I have to know about the new directory first, and I have to do this for every new directory.
Is there an efficient way to get a complete update, including any newly-added directories, from a CVS server?
Use a shell script which generates a custom $CVSIGNORE list for this type of update, then runs cvsupdate -d to do this:
CVS has a list of files (or sh(1) file name patterns) that it should ignore while running update, import and release. This list is constructed in the following way.
The list is initialized to include certain file name patterns: names associated with CVS administration, or with other common source control systems; common names for patch files, object files, archive files, and editor backup files; and other names that are usually artifacts of assorted utilities. Currently, the default list of ignored file name patterns is:
RCS SCCS CVS CVS.adm
RCSLOG cvslog.*
tags TAGS
.make.state .nse_depinfo
*~ #* .#* ,* _$* *$
*.old *.bak *.BAK *.orig *.rej .del-*
*.a *.olb *.o *.obj *.so *.exe
*.Z *.elc *.ln
core
The per-repository list in ‘$CVSROOT/CVSROOT/cvsignore’ is appended to the list, if that file exists.
The per-user list in ‘.cvsignore’ in your home directory is appended to the list, if it exists.
Any entries in the environment variable $CVSIGNORE is appended to the list.
Any ‘-I’ options given to CVS is appended.
As CVS traverses through your directories, the contents of any ‘.cvsignore’ will be appended to the list. The patterns found in ‘.cvsignore’ are only valid for the directory that contains them, not for any sub-directories.
In any of the 5 places listed above, a single exclamation mark (‘!’) clears the ignore list. This can be used if you want to store any file which normally is ignored by CVS.
References
Ignoring files via cvsignore