Search code examples
gitgitignore

Git: ignore file.ext1 only if file.ext2 exists


To be precise, there is a project with a bunch of *.el and *.org files. When executed, from every file.org a file.el is generated. Now the .gitignore is being written. Is there a possibility to say that any file.el shall be ignored only if file.org is there, otherwise track file.el

This does not solve it. Neither does writing every single file in the .gitignore


Solution

  • Not with gitignore (I don't know of conditional ignore rules).

    A workaround would be a bash script (works even on Windows) which would:

    • find all file.el
    • for each file, test if file.org exists
    • if it does, use git update-index --no-assume-unchanged file.el

    (or git skip-worktree --no-assume-unchanged file.el: see "Difference Between 'assume-unchanged' and 'skip-worktree'"

    But, as commented, it would be easier to separate generate from dist files, with only the former to be ignored.