I’ve been using git for work lately and became frustrated with the behavior of the git difftool command when trying to view changes. The default behavior is that each individually modified file will be passed to your difftool of choice and the next file will not be presented to you until closing the tool. I use beyond compare as my merge and diff tool and was used to having all modified, added, or deleted files showing up inside beyond compare so that I could freely bounce around tabs and view the entire changeset. I stumbled upon this blog post which almost had the behavior I wanted but only parses for modified files which means added, deleted, or moved files are missed. I’ve aliased the below batch script gda in my dotfiles which has come in handy the past few weeks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/usr/bin/env bash set -euo pipefail # Store workspace root since git diff prints files based on root of project WORKSPACE_ROOT=$(git rev-parse --show-toplevel) # get names of changed files # print zero-terminated filenames # read zero-terminated filenames and ignore escape sequences # and diff them git diff --name-status "$@" | while read status ; do IFS=$'\t' tokens=( $status ) # Modified, added, or deleted files if [[ ${tokens[0]} =~ ^[MAD] ]]; then git difftool --no-prompt "$@" -- "${WORKSPACE_ROOT}/${tokens[1]}" & # Renamed files elif [[ ${tokens[0]} =~ ^R ]]; then git difftool --no-prompt -M "$@" -- "${WORKSPACE_ROOT}/${tokens[1]}" "${WORKSPACE_ROOT}/${tokens[2]}" & fi done |