Conditional Gitignore

I have a git repository that stores my personal documents. Some of these documents are LaTeX files, and some are even PDF files. Of course, I want them to be in my repo documents.

But when I create an org-mode document ( *.org ), I often create it, as a result, these files are created if the org-mode document is called α :

  • α.tex
  • α.pdf
  • auto / α.el

I do not want to track them, because they are generated files from which I have source code, but I can’t just ignore all *.tex and not even all *.pdf files.

Can .gitignore ignore every file named α.tex or α.pdf if there is a file named α.org with α that is a variable for an arbitrary string?

+5
source share
1 answer

This is not possible .gitignore is a fairly simple file and does not allow any conditional rules.

However, as a rule, it is a good idea to prepare the assembly system to create all the intermediate files in any assembly. Often used build or target . Then you can just put in .gitignore :

 /target # / specifies the root path /auto # probably your temporary files...? 

If compilation is done using the Makefile, the rules may look like this:

 target/%.pdf: target/%.tex $(LATEX) -o $@ $< target/%.tex: %.org generate_tex -o $@ $< 

(not much about the syntax for latex and, of course, the specific command to generate *.tex from *.org )

+3
source

Source: https://habr.com/ru/post/1261220/


All Articles