I'm managing several pdf
and graffle
files with git. I want to add pdf
files to repository only if graffle
with same filename does not exists, e. g.
only add foo.pdf
and bar.graffle
into repository in the directory
$ ls
foo.pdf
bar.pdf
bar.graffle
If such target can't be completed only with gitignore
, is there any work arounds exist?
bar.pdf
can only be generated with bar.graffle
through several steps in GUI, so I want to keep them on commit.
Note that
.gitignore
only exists as a hint togit
as to which files, directories or file types will be ignored bygit add
.However,
.gitignore
will not stop any file to be added into repository if you usegit add -f
.Long story short,
.gitignore
is rather simplistic mechanism that helps to avoid accidentally adding typical junk files (like editor backups, object files, executables, etc.), but it is not sophisticated enough to be capable of what you are asking for - like changing behaviour depending on some external conditions.You can be careful not to add some files if you don't want them, or add ignored files with
git add -f
and thus overriding existing simple rules.Alternatively, you can create some script and register it as git macro like
git addc
that will do such advanced filtering.