In a project where for instance a parser is involved, some source code is the product of a program. For instance yacc
generates - based on a .yy
file - a source code file that implements the parser.
Since small modifications in the .yy
file can lead to large changes in the corresponding source code file after compilation and since the resulting source code is (almost) never altered after it is generated. Such source code files are perfect candidates for the .gitignore
list.
Now one can of course write such files manually to the list:
lexer1.cpp
parser1.cpp
lexer2.cpp
parser2.cpp
But it is likely when one builds a new parser, he/she will forget to add the file to the list.
Is there a way to specify a pattern that acts as follows:
Given a file
foo.ext1
exists, ignorefoo.ext2
.
Where one thus provides ext1
and ext2
. In the case of the lexer/parser, this would mean applying this pattern for .xx
/.cpp
and .yy
/.cpp
.
This is probably not possible by .gitignore
directly, but perhaps there are some hooks already implemented for this?
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
. gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.
A file with the GITIGNORE file extension is a Git Ignore file used with the version/source control system called Git.
I can see three ways to do this -- to answer the question directly, no, ignore processing consults only the pathname in question, not anything else about the environment.
Put your generated source in a generated
folder you ignore.
Me, I like this one best, I know I'm in a minority but I don't like build detritus in my source directories.
Have your makefile targets also update the .gitignore
, with
grep -qs ^target$ .gitignore || echo target >>.gitignore
where target
is the generated source file, as part of the recipe.
put some marker in the generated filenames themselves, scanner.generated.c
or something.
For some reason I really dislike the pre-commit hook cleaning out unwanted source, git deleting things from a commit all by itself is just disturbing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With