I try to ignore file in a directory by relative path. E.g. I have several directories in working tree lib/file.f
and I want all occurrences of this file to be ignored. I tried
lib/file.f
but this does not work.
A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .
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 file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.
Place
*/lib/file.f
in your .gitignore
. This will cause git to ignore any file of the form project/<DIR>/lib/file.f
, assuming .gitignore
is in the project
directory.
To make git ignore lib/file.f
two directories down, you'd also have to add
*/*/lib/file.f
to the .gitignore
, and so on.
Vastly simpler of course, would be to place
*file.f
in .gitignore
to block all files named file.f
, but your question seems to suggest there is at least one file by that name you wish not to ignore.
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