Posts Tagged ‘diff’

git-difftool: an easy way to highlight changes in git-managed text files

In two previous posts (post one, post two) we have shown how to use git latexdiff and latexdiff to visually highlight the differences of a Latex file in between its different versions in the form of a Latex-compiled diff file. For comparing arbitrary textfiles instead of Latex files, no Latex-based visual comparison is available. However, git itself ships a nice little tool to compare two different versions of the same textfile and highlight its differences: git difftool. It basically does two things for you:

  • Checkout the versions of the file to compare
  • Fire up your diff program to show you/highlight the differences

All you need to do is specify the file and the versions you want to compare.



git difftool is part of the git installation. However, it needs to know which diff program you want to use when calling git difftool. You can specify this by adding the following snippet to your ~/.gitconfig:

    tool = MY-DIFF-TOOL

where MY-DIFF-TOOL could be vimdiff, kdiff3, or similar (ensure the tool you specify is installed and available in the PATH on your machine). Now git difftool should be ready for usage:

user@machine:~$ git difftool -h
usage: git difftool [-t|--tool=] [--tool-help]
                    [-g|--gui] [--no-gui]
                    [--prompt] [-y|--no-prompt]
                    ['git diff' options]


git difftool has a simple call syntax (in fact the same as git diff). The command you might want to compare files might be similar to this:

git difftool COMMIT1 COMMIT2 FILE

If you use


as COMMIT1 and leave out COMMIT2 you will see the differences between the file in its current, possibly unstaged/uncommited stage and its last commit. If you specify a hash for COMMIT1 and use


as COMMIT2 you will see the differences of the current file to the specified commit instead. If you specify hashes for both COMMIT1 and COMMIT2 you will see the differences between those two versions of the file.

Data backups: diff, rdiff-backup etc.

February 28, 2015 Leave a comment

diff: differences between source and destination folder

Imagine you already some 1:1 backup, e.g. your data partition copied to a backup disk. You did that without using rdiff-backup or similar, just a plain copy. If you now want to see differences between the source and destination directory the following diff command might come in handy. It lists the differences in content between dir1 and dir2 – recursively and with modified output (we assume you just want to know which files changed, and not how files changed). This could be useful to see which files “disappeared” since doing the backup (accidentally deleted etc.)

diff -ur dir1 dir2 > diff.txt

rdiff-backup: easy to use incremental backups

When backing up bigger portions of data, incremental backups can greatly speed up the process. rdiff-backup provides such incremental backups and is fairly easy to use. Further, rdiff-backup always represents the latest version of your content in the backup, alongside reverse diffs to go back to older versions.

The rdiff-backup syntax works the “include all content in the specified source directory to the backup, exclude only additionally specified files/folders”-way. For my personal data backup I do it the other way round, as I only have a hand full folders to include in the backup, which are distributed all over the file system. I first include all locations I want backupped, then exclude everything else (“/**”) and specify the file system root as source directory. The following command is adapted to my personal needs (and really only backups data, no system configuration or else), so you will need to adapt it to fit your needs:

rdiff-backup --include /media/data/documents --include /media/data/pictures --include /media/data/music --include /media/data/new --include /media/data/tools --include /media/data/virtualOS --include /home/xxx/.thunderbird --include /home/xxx/git_repos --exclude /** / /path/to/backup

You can include your data partitions here, as well as do a data backup of essential parts of your system by including /etc, /home, /root etc.

latexdiff-git: highlight changes between revisions of latex files managed in git

July 31, 2014 1 comment

latexdiff is a useful tool to determine changes between different versions of latex files and highlight them in a pdf (similar to MS word does with tracking changes). latexdiff-git is a wrapper around latexdiff optimized for git (and mercurial, but we’ll only look into git here). With it you can specify a latex document file (which is in a git repository) and a commit hash from that repository to look for changes between the file and its version from the specified commit. Same is possible with e.g. specifying two different commit hashes.

Installation (Linux)

  1. Clone latexdiff-git
    git clone
  2. All further steps are stated in the README file inside the repository you just cloned:
    1. Ensure you have a ~/.gitconfig file and that it’s accessible for your user.
    2. Add the following lines to .git/config
       cmd = latexdiff "$LOCAL" "$REMOTE"
       prompt = false
       ldiff = difftool -t latex
    3. Change the checked out script file search for revlatexdiffcmd='please define' and replace it with revlatexdiffcmd='git ldiff'
  3. Place somewhere in your path (I tend to place it in ~/bin) and make it executable: chmod +x


You can generate a tex file from differences between a latex file and a revision checked into git with (replace GITHASH and FILE with your git commit hash and latex file)

latexdiff-git -r GITHASH FILE

Alternatively you can generate the tex file from changes between two specific commits of a latex file:

latexdiff-git -r GITHASH1 -r GITHASH2 FILE

To view changes hightlighted in a pdf:

pdflatex *diff*tex # create pdf highlighting diff
evince *diff*pdf # replace evince with your preferred pdf-viewer
Categories: Misc Tags: , , , , , ,