Is it possible? The git update-index --assume-unchanged
is no solution, ignored files have to be tracked. Creating submodules either.
E.g.
cat .customgitignore(1|2|3...)
i-do-not-need-this.extension
cat .gitignore
basic-stuff.extension
<load> .customgitignore1
<load> .customgitignore2
<load> .customgitignore3
etc
Issue description for those interested.
I am creating private repo of configs. One branch = one config. Additional branch as workspace. I merge other branches-configs with workspace depending on requirements. Branches-configs each have their own .gitignore which should be applied only after merge. I am trying to omit conflicts in gitignore file.
I am trying to omit conflicts in gitignore file
Then don't version the final .gitignore file itself: generate it on demand.
Keep your .gitignore files separates, but add a content filter driver (a smudge
script), which will:
As Git doesn't support this out of the box, you may implement one yourself with Git hooks, for example:
In any case, you will need to manage your ignores and includes in a custom file, not a .gitignore
itself, as this one will be generated. So, let's say, you have a .gitignoreincludes
file in a branch, and custom include files in other branches.
So, you may install a "post-merge" hook like this, for example:
#!/bin/bash
gitignoreWithIncludes=".gitignoreincludes"
if [[ -f $gitignoreWithIncludes ]]; then
echo ".gitignore" > .gitignore
while read -r line
do
if [[ $line == include* ]]; then
includeName=${line:8}
while read -r includeLine
do
echo $includeLine >> .gitignore
done < $includeName
else
echo $line >> .gitignore
fi
done < $gitignoreWithIncludes
fi
This hook will launch on any successful merge, will look for a .gitignoreincludes
file, and, if it exists, will generate a .gitignore
file. .gitignore
will contain all entries from .gitignoreincludes
and all entries from all files referenced as include FILE_NAME
. Having .gitignore
ignoring itself allows it to be safely regenerated multiple times when doing merges.
This can be further improved by allowing include
instructions in included files as well, or also a post-checkout
hook can be implemented to regenerate the .gitignore when switching between branches, etc., etc..
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