Skip to content

Instantly share code, notes, and snippets.

@kekru
Last active December 16, 2024 12:55
Show Gist options
  • Save kekru/28bb284add91e8dd8a2fd2488310e6ec to your computer and use it in GitHub Desktop.
Save kekru/28bb284add91e8dd8a2fd2488310e6ec to your computer and use it in GitHub Desktop.
Diff .tar.gz files in vscode

Diff .tar.gz files in vscode (and other git clients)

Tested on Windows, but should also work on Linux and Max

  1. Store the targzDiff.sh from below somewhere on your computer
  2. Add to your ~/.gitconfig with path to local stored targzDiff.sh
[diff "targz"]
  textconv = sh -c 'cat $0 | ~/some/where/targzDiff.sh'

(~ is on Windows C:\Users\<Username>\)

  1. Add the following to either your project's .gitattributes or global ~/.gitattributes (when configured [core] attributesfile = ~/.gitattributes)
**/*.tar.gz binary diff=targz
  1. Now open vscode or any other git diff tool and click on a commit -> it will show diff of the textfiles inside the .tar.gz
  2. Inside the targzDiff.sh currently m.p4, .jpg and .png are excluded -> add more binaries to the if statement if you need to exclude more
#!/bin/bash
set -euo pipefail
tarGzFilePath="/dev/stdin"
timestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
extractPath="/tmp/${timestamp}-${RANDOM}-targzDiff/"
mkdir -p "$extractPath"
tar -xzf "$tarGzFilePath" -C "$extractPath"
find "$extractPath" -type f | while read -r file; do
if [[ "$file" != *.mp4 && "$file" != *.jpg && "$file" != *.png ]]; then
echo "Content of $(basename "$file"):"
cat "$file"
echo -e "\n\n"
else
echo "binary $(basename "$file"), hashcode:"
sha256sum "$file" | awk '{print $1}'
fi
done
rm -rf $extractPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment