简体   繁体   中英

How to git ignore file with same name as container directory?

The file named as "project" is resultant of a build which produces a binary file with the same name as the container directory:

project/
    src/
    main.c
    project <-- binary file, same name as container directory

Being more general, how to ignore a file that have the same name as their container directory? Keep in mind that if "project" directory is renamed the resultant built file will change name too.

To match files with the same name as their containing directory you'd need a language more powerful than the shell globs that .gitignore uses, like regular expressions with backreferences.

The question of how to use regular expressions in .gitignore has been asked before ( Example ) and the answer has always been "You can't."

Get used to the idea that you have to update your .gitignore when you rename a directory.

You can specify a path starting with the root git directory in .gitignore . So for your example, you could put

/project/project

in your .gitignore . I'm not sure if there's a way in git to see the repository name and ignore same-names files, but since it seems like you're using a script (or makefile or whatever) to build what you're keeping in the repository, you should be able to write to .gitignore from that script. Something like

echo $projName"/"$projName > .gitignore

would work. You'd need to specify the location of .gitignore , depending on where your makefile/script is located.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM