How can git ignore a file with the same name as the container directory?
A file named "project" is the result of a build that creates a binary file with the same name as the container directory:
project/
src/
main.c
project <-- binary file, same name as container directory
To be more general, how to ignore a file with the same name as in its containers directory? Note that if you rename the "project" directory, the resulting embedded file will also change the name.
source to share
You can specify a path starting at the git root directory in .gitignore
. So for your example, you can put
/project/project
in .gitignore
. I'm not sure if there is a way in git to see the repository name and ignore files with the same name, but since it seems that you are using a script (or makefile or whatever) to create what you are storing in the repository, you should be able to write .gitignore
from this script. Something like
echo $projName"/"$projName > .gitignore
will work. You need to provide a location .gitignore
, depending on where your makefile / script is located.
source to share
To match files with the same name as their containing directory, you need a language more powerful than the shells used by .gitignore, such as regex with backreferences.
The question of how to use regular expressions in .gitignore has been asked before ( Example ) and the answer was always "You can't".
Get used to the idea that you need to update your .gitignore when you rename a directory.
source to share