Skip to content

Instantly share code, notes, and snippets.

@beli-sk
Last active April 17, 2026 08:39
Show Gist options
  • Select an option

  • Save beli-sk/e9811488945d0d899014714e4f72298d to your computer and use it in GitHub Desktop.

Select an option

Save beli-sk/e9811488945d0d899014714e4f72298d to your computer and use it in GitHub Desktop.
git diff for SOPS encrypted file
#!/bin/bash
set -eo pipefail
ref="$1"
fname="$2"
if [[ -z "$fname" || "$ref" == "-h" || "$ref" == "--help" ]] ; then
echo "git diff for SOPS encrypted file"
echo "use: git-sops-diff <commit> <path>"
echo "compares working tree file to version in specified commit"
exit 1
fi
ftype="${fname##*.}"
[[ "$fname" != */* ]] && fname="./${fname}"
tmpf1=`mktemp --tmpdir worktree.XXXXXX`
tmpf2=`mktemp --tmpdir commit.XXXXXX`
cleanup() { rm "$tmpf1" "$tmpf2" ; }
trap cleanup EXIT
sops -d "$fname" > "$tmpf1"
git show "${ref}:${fname}" | sops -d --input-type "$ftype" --output-type "$ftype" /dev/stdin > "$tmpf2"
diff -u "$tmpf2" "$tmpf1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment