Created
July 29, 2025 03:16
-
-
Save dezza/077b241204512d641f1ace4deaaaa8b6 to your computer and use it in GitHub Desktop.
Save a git repo state in a sha256sum by tracking all unmodified, modified, deleted, staged, unstaged, untracked, ignored files as well as config, notes, submodules, worktree, remotes, excludes, heads, branches, stash, hooks and packed-refs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save repo state | |
git_repo_hash() { | |
set -- "${1%/}" # remove trailing slash | |
{ | |
cat "$1/.git/logs/HEAD" "$1/.git/ORIG_HEAD" "$1/.git/packed-refs" \ | |
"$1/.git/refs/heads/*" "$1/.git/refs/remotes/*" "$1/.git/refs/stash" \ | |
"$1/.git/logs/refs/stash" "$1/.git/hooks/*" "$1/.git/info/exclude" \ | |
"$1/.git/refs/tags/*" 2>/dev/null | |
git -C "$1" ls-files --modified --deleted --others | |
git -C "$1" ls-files --stage # "$1/.git/index in ASCII | |
git -C "$1" config --local --list | grep -E '(user\.|core\.|remote\.)' | |
git -C "$1" notes list 2>/dev/null || true | |
git -C "$1" submodule status 2>/dev/null || true | |
git -C "$1" worktree list 2>/dev/null || true | |
} | sort | sha256sum | sed "s# -#$1#" | |
} | |
# source git_repo_hash.sh; git_repo_hash ~/src/lang/project/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment