#!/bin/sh # SPDX-License-Identifier: MIT set -eu export TZ=UTC LC_ALL=C export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null export GIT_AUTHOR_NAME='Example Author' export GIT_AUTHOR_EMAIL='author@example.invalid' export GIT_COMMITTER_NAME='Example Author' export GIT_COMMITTER_EMAIL='author@example.invalid' export GIT_AUTHOR_DATE='2026-10-25T12:00:00+00:00' export GIT_COMMITTER_DATE='2026-10-25T12:00:00+00:00' test "$(git version)" = 'git version 2.56.0' mkdir unstage-example cd unstage-example git init -q --template= --initial-branch=main --object-format=sha1 git config commit.gpgsign false git config core.autocrlf false printf 'base\n' > note.txt git add note.txt git commit -qm 'Base note' head_before=$(git rev-parse HEAD) printf 'base\nstaged line\n' > note.txt git add note.txt printf 'later edit\n' >> note.txt printf 'new file\n' > draft.txt git add draft.txt file_before=$(git hash-object note.txt) new_before=$(git hash-object draft.txt) printf 'Before: one staged addition and one twice-edited file\n' git status --short git diff --cached -- note.txt git diff -- note.txt git diff --cached -- note.txt > staged.patch test -s staged.patch git restore --staged -- note.txt test "$(git rev-parse HEAD)" = "$head_before" test "$(git hash-object note.txt)" = "$file_before" test "$(git show :note.txt)" = base test "$(git status --porcelain=v1 -- note.txt)" = ' M note.txt' printf 'Tracked file: all local lines remain; none are staged\n' git diff --cached -- note.txt git diff -- note.txt git restore --staged -- draft.txt test "$(git hash-object draft.txt)" = "$new_before" test "$(git status --porcelain=v1 -- draft.txt)" = '?? draft.txt' printf 'New file: still present, now untracked\n' git status --short git diff --cached --exit-code git add note.txt test "$(git show :note.txt)" = "$(cat note.txt)" printf 'Restaging takes the current complete note.txt content\n' git diff --cached -- note.txt