In .gitignore I have a rule that excludes a path settings.php
However, that rule has to be disregarded (the file has to be included in git), but for special reasons (the .gitignore file gets frequently reset to default from outside) I prefer not to change the .gitignore itself, but rather to override it by setting a counter-rule in the core.excludesfile file.
So in the relevant core.excludesfile file I put: !settings.php
to override the above rule. But it does NOT work. I suspect that rules in .gitignore have priority over the ones in the global file with exclusions (this is how I understand https://www.kernel.org/pub/software/scm/git/docs/gitignore.html).
Is there any way to override a rule set in .gitignore by a rule in core.excludesfile or elsewhere?
You can edit your . gitignore file for your repo by going to the Settings view in Team Explorer, then selecting Repository Settings. Select Edit for your . gitignore .
The easiest and most common way to ignore files is to use a gitignore file. Simply create a file named . gitignore in the repository's root directory. Then, add names and patterns for any files and directories that should not be added to the repository.
To ignore untracked files, you have a file in your git folder called . git/info/exclude . This file is your own gitignore inside your local git folder, which means is not going to be committed or shared with anyone else. You can basically edit this file and stop tracking any (untracked) file.
Yes! It turns out that when adding a file to a repository you can force it to override .gitignore:
git add -f <filename> or git add --force <filename>
Source: https://www.kernel.org/pub/software/scm/git/docs/git-add.html
There is an easy way how to override rules in a .gitignore file -- simply make a new .gitignore file on a deeper level. E.g. in my case I was able to make git ignore my settings.php file by adding "!settings.php" into a new .gitignore file in the same folder where settings.php lives.
Reference: https://git-scm.com/docs/gitignore
An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".
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