Useful when teachers require that you "include in the report the most important code that you yourself wrote or modified."
For each file it creates a heading (like section/subsection -- is customizeable) and a label with the filename (also customizeable)
- Python 3.2+
- a TeX enviroment
$ git diff --no-color > somefile.diff
$ SOMEPATH/difftotex.py somefile.diff
or
$ git diff --no-color | SOMEPATH/difftotex.py
This will create the file diff.tex
in your current directory.
========================
To change the path of output file, use the -o
options, like so
$ SOMEPATH/difftotex.py -o path/output.tex somefile.diff
- adding options to the end is also accepted
========================
To learn about the "advanced" options run SOMEPATH/difftotex.py --help
(like changing the section level to "subsubsection")
Include the following in your preabmle
\usepackage{array}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[table]{xcolor}
and then input the diff
\input{diff.tex}
Here is a small example for a libgit2 commit -- below is a preview of the pdf
- Can only parse git diffs (not other formats)
- Will completely ignore binary files listed in the diff
- Tab size is fixed to 4 spaces
- TeX code gets really ugly (special characters are escaped manually, due to the fact that I couldn't find a combination of multipage tables working with an in-cell verbatim enviroment)
You need to specify a reference to the commit you want to base your diff on, lets call it <start-commit>
. To generate the diff up till the current commit, simply run git diff --no-color start-commit
-- you can also specify a commit to end at, as git diff --no-color start-commit end-commit
run git rev-list --max-parents=0 HEAD
to list all root commits (there can be more than one)
If you want to restrict paths included, e.g. only include folders src
and data
, run git diff --no-color start-commit end-commit -- src data
When you want <git-project>/src/file.c
listed as file.c
, cd to <git-project>/src/
and add the --relative
option. (will restrict diff to current folder and subfolders)
Add the option -U10000000
(will include the nearst 10,000,000 lines of code)
Add the option -W