0

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.

Haocheng
  • 1,323
  • 1
  • 9
  • 14

1 Answers1

6

Note that .gitignore only exists as a hint to git as to which files, directories or file types will be ignored by git add.

However, .gitignore will not stop any file to be added into repository if you use git 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.

mvp
  • 111,019
  • 13
  • 122
  • 148
  • A great explanation. But I think it's also necessary to add that ignored files also won't be visible for `git status`. If you want to check ignored files you should use `git status --ignored`. – Viacheslav Kondratiuk Dec 26 '12 at 10:47