A deployment script can stop launching even when nobody edited its text. Git stores the executable distinction in the tree entry, separately from the blob that contains the bytes. Comparing only the blob IDs misses that change. You can demonstrate the difference in a disposable repository without creating commits or touching a real project's index.
Write two trees from one staged file
Use Bash and a Git release supporting git ls-tree --format, such as Git 2.43. Save this as tree.sh and run from a writable scratch directory outside an active Git hook or alternate-index session. The temporary repository lives under the current directory and is removed by the exit trap.
#!/usr/bin/env bash
set -eu
repo=$(mktemp -d ./tree-demo.XXXXXX)
trap 'rm -rf -- "$repo"' EXIT
(
cd "$repo"
git init -q --template=
printf 'fixture\n' > runner
git add -- runner
git update-index --chmod=+x -- runner
executable=$(git write-tree)
git update-index --chmod=-x -- runner
plain=$(git write-tree)
a=$(git ls-tree --format='%(objectmode) %(objectname)' "$executable" -- runner)
b=$(git ls-tree --format='%(objectmode) %(objectname)' "$plain" -- runner)
test "${a%% *}" = 100755
test "${b%% *}" = 100644
test "${a#* }" = "${b#* }"
test "$executable" != "$plain"
printf '%s -> %s; same blob\n' "${a%% *}" "${b%% *}"
)Run:
GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 bash tree.shExpected output:
100755 -> 100644; same blobWhat changed and what stayed the same
git update-index --chmod changes the staged executable bit explicitly. git write-tree writes a snapshot of the staged state. In the two snapshots, the regular-file mode changes from executable to non-executable and the blob ID stays the same. The tree IDs differ because those IDs cover the entries, including their modes. Comparing the actual IDs instead of their length makes the test independent of a particular hash format.
Troubleshoot a real checkout
To inspect a committed state, pass its tree or commit to git ls-tree and compare the mode and object ID for the same path. Start from the repository root when copying the example's relative path lookup. A missing path produces no row and is not a non-executable result. A symlink or submodule is a different kind of tree entry and should not be interpreted as an ordinary executable file. If the staged bit is correct but a deployed file cannot execute, check how the checkout or artifact packaging preserved permissions. This fixture tests Git's recorded state, not execution of a shell script or the behavior of a deployment filesystem.
Primary references and related tutorials: git ls-tree · git update-index · Java Samples Git tutorials.