I am currently working on a project with multiple people via github. For the code this works as expected. however we also have to write a report and would like to do this in the same repository.
The problem now is that while the merging of different changes works great with the tex file, even the simplest changes create problems while merging the pdf file (as expected).
Our solution so far has been to add *.pdf
files to the .gitignore
. However this leads to us having to recompile the output before being able to view it, which would just be more convenient in case we would simply want to check the newest changes in the pdf.
Is there a way to prevent git from trying to merge the changes in the pdf and simply overwriting the existing file with the new version while merging the .tex
file?
I know this is not a terrible solution, I'm simply looking for a more elegant solution.
In general, no, Git doesn't offer a functionality for this. Git offers regular three-way merges (in a variety of formats), a mode to always conflict if the files are different, or a custom merge driver. (You can look at the merge
settings in the gitattributes(5)
manual page for more details.) None of those does what you want.
The Git developers would recommend that you do what you're doing now, which is to simply check in the source (the .tex
file) and ignore the PDF and build it on demand. You should avoid checking in build products, such as your PDF, to the repository, because it bloats the repository, it causes conflicts on merges, and the source and binary can easily drift.
You can avoid needing to rebuild the PDF unnecessarily by using a makefile. Here's an example of one that I've configured for my resume using GNU make:
XELATEX = xelatex
SRC = $(wildcard *.latex)
PDF = $(SRC:.latex=.pdf)
all: $(PDF)
%.pdf: %.latex
$(XELATEX) $<
Simply typing make
will rebuild the PDF if necessary, and do nothing if nothing needs to be done. In general, unless your report is very large, LaTeX should take only a few seconds, if that, and so the cost of building it when it changes should be minimal.